Why is my React App not serving with PM2? - javascript

I am trying to run my React App with PM2 on an Ubuntu server. It has been running fine for years before today, and suddenly it stopped.
The one change I made today was that I reset my root password. But I can't think why that would make a difference.
I have created the app build.
If I just serve the app from the root directory of the application with serve -s build it serves correctly.
Then I try to serve the file using PM2 with a file 'ecosystem.config.js' that in my server root directory. This is the module:
apps : [{
name:'myapp',
script: '../../var/www/myapp',
interpreter : 'none',
args: 'sudo serve -s build',
watch: true,
env: {
NODE_ENV:'development',
},
env_production : {
NODE_ENV: 'production'
}
}]
}
I run pm2 restart all and it seems to restart, but then it errors.
The log shows the following:
at WriteStream.emit (events.js:210:5)
at internal/fs/streams.js:299:10
at FSReqCallback.oncomplete (fs.js:146:23)
Error: Cannot find module '/var/www/myapp'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:794:15)
at Function.Module._load (internal/modules/cjs/loader.js:687:27)
at /usr/local/lib/node_modules/pm2/lib/ProcessContainer.js:297:23
at wrapper (/usr/local/lib/node_modules/pm2/node_modules/async/internal/once.js:12:16)
at next (/usr/local/lib/node_modules/pm2/node_modules/async/waterfall.js:96:20)
at /usr/local/lib/node_modules/pm2/node_modules/async/internal/onlyOnce.js:12:16
at WriteStream.<anonymous> (/usr/local/lib/node_modules/pm2/lib/Utility.js:186:13)
at WriteStream.emit (events.js:210:5)
at internal/fs/streams.js:299:10
at FSReqCallback.oncomplete (fs.js:146:23)```
Thank you for any ideas.

Related

We're sorry but sf doesn't work properly without JavaScript enabled. Please enable it to continue

I have a Vuejs app that makes an Axios call. I Dockerized it and used digitalocean to serve it to the cloud. App is working but after any axios call, i am getting "We're sorry but sf doesn't work properly without JavaScript enabled. Please enable it to continue." as response.
-I have tried changing the port from 8080 to 8081, running the app on incognito browser tab, changing "baseUrl" with "baseURL" and in front-end docker file i was installing libraries with npm, i also tried to use yarn but i still have this issue.
Is there any more idea about how to fix it ?
main.js file
createApp(App)
.use(store)
.use(vue3GoogleLogin, {
clientId:
"******",
})
.component("font-awesome-icon", FontAwesomeIcon)
.component("MazBtn", MazBtn)
.component("MazInput", MazInput)
.component("MazPhoneNumberInput", MazPhoneNumberInput)
.component("Datepicker", Datepicker)
// .component("VueGlide", VueGlide)
.use(router)
.mount("#app");
Frontend Docker file ;
#Base image
FROM node:lts-alpine
#Install serve package
RUN npm i -g serve
# Set the working directory
WORKDIR /app
# Copy the package.json and package-lock.json
COPY package*.json ./
# install project dependencies
RUN npm install
# Copy the project files
COPY . .
# Build the project
# Build the project
RUN npm run build
# Expose a port
EXPOSE 3000
# Executables
CMD [ "serve", "-s", "dist" ]
Backend docker file
FROM python:3.10-bullseye
# Working directory
WORKDIR /app
# Copy the dependencies
COPY ./docs/requirements.txt /app
# Install the dependencies
RUN pip3 install -r requirements.txt
# Copy the files
COPY . .
WORKDIR /app/backend
ENV FLASK_APP=app.py
# Executable commands
CMD [ "python3", "-m" , "flask", "run", "--host=0.0.0.0"]
vue.config.js file ;
const { defineConfig } = require("#vue/cli-service");
module.exports = defineConfig({
transpileDependencies: true,
devServer: {
compress: true,
host: "127.0.0.1",
proxy: {
// "/upload/img": {
// // target: "http://127.0.0.1:9000",
// target: "http://127.0.0.1:5000",
// },
"/api": {
// target: "http://127.0.0.1:9000",
target: "http://127.0.0.1:5000",
},
"/media": {
target: "http://localhost:8000",
},
"/http-bind": {
target: "https://localhost:8443",
logLevel: "debug",
},
},
// https: true,
// watchContentBase: false,
},
});
Your backend requests are being handled by the frontend app. It looks like you are relying on the development server's proxy functionality in order to forward them to the backend, but this will (and should) not be active when you deploy your app. Instead you will need another proxy that sends /api requests to your backend and other requests to your frontend.

pm2 deprecated worker on cluster mode

I was going in order to create a Small Discord Bot, and i'm using PM2 to watch and restart the bot. SO yesterday i setted a process file in order to use the clustermode to open more istances.
Until yesterday all works good with no worries.
Today when i launch the process file, it opens a terminal window for each istance that i have, and each time i save a file and PM2 will restart the bot, it gives the error:
[DEP0007] DeprecationWarning: worker.suicide is deprecated. Please use worker.exitedAfterDisconnect.
For each istance. I searched online but any thread could not helped me, i also reinstalled the latest version of pm2:
pm2 update
or
npm install -g pm2#latest --save
i also uses the command line insted of the process file:
pm2 start index.js -i 4 --name myapp --watch
but nothing, when i goes on pm2 logs, on restart it gives that error.
How can i solve this?
My Process file:
module.exports = {
apps : [{
name: 'Economy',
script: 'index.js',
instances: 4,
exec_mode: "cluster",
autorestart: true,
watch: true,
ignore_watch: ["database"],
max_memory_restart: '1G',
env: {
NODE_ENV: 'development'
},
env_production: {
NODE_ENV: 'production'
}
}],
};
According to https://github.com/Unitech/pm2/issues/3597:
If you're using Node version <= 8, you can ignore the warning (it's a warning, not an error) OR upgrade to Node version >= 9. (Reminder: Node LTS is currently version 10).

How to run openshift MEAN project in localhost or development system Ubuntu?

I have created a MEAN stack application on https://openshift.redhat.com/ and it was successfully running on the web.
Default source code of the project synced form: https://github.com/linnovate/mean-on-openshift.git
For further development I am cloning the hosted git source using using git url mentioned in the applications page. (e.g git clone ssh://55e86e9f89f5cf1d29000001#nodejs-tapslab.rhcloud.com/~/git/nodejs.git/).
After clone the source code to local system, opening the project in sublime text editor. I can see in the config/env/development.js there are lot of configuration are used like process.env.OPENSHIFT_XXX. I was changed the some config value mentioned below and trying to start server using command : 'node server', but server was not starting throwing error.
{
db: db: 'mongodb://' + (process.env.DB_PORT_27017_TCP_ADDR || 'localhost:27017') + ':' + '/mean-dev',
hostname: process.env.OPENSHIFT_NODEJS_IP || 'http://localhost:3000'
}
Can someone help me how to run Openshift mean project in local system and what all configuration needed before running it in local system.
System Config :
Ubuntu 12.04
MongoDB v2.6.6
Nodejs v0.10.40
npm 1.4.28
grunt-cli v0.1.13
Error :
$ node server
Mean app started on port 3000 (development)
events.js:72
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND
at errnoException (dns.js:37:11)
at Object.onanswer [as oncomplete] (dns.js:124:16)
Git:
$ NODE_ENV=test node server

Deploy sails.js on Openshift

I'm trying to deploy a sails.js app (sails.js version 0.11) to Openshift.
I'm aware of the previous questions and answers in here for example;
https://gist.github.com/mdunisch/4a56bdf972c2f708ccc6
I followed the steps from that post.
I also created my app via git://github.com/ryanj/nodejs-custom-version-openshift.git so I have minimum npm version required by sailsjs. Still the application doesn't start. Has anybody attempted deploy sails v0.11 app on openshift before?
Thank you
I see below in the logs
DEBUG: Running node-supervisor with
DEBUG: program 'server.js'
DEBUG: --watch '/var/lib/openshift/55a4256b5973cadc8400000d/app-root/data/.nodewatch'
DEBUG: --ignore 'undefined'
DEBUG: --extensions 'node|js|coffee'
DEBUG: --exec 'node'
DEBUG: Starting child process with 'node server.js'
DEBUG: Watching directory '/var/lib/openshift/55a4256b5973cadc8400000d/app-root/data/.nodewatch' for changes.
Listening on 127.2.103.1, port 8080
DEBUG: Sending SIGTERM to child...
My solution as explained here works.
https://github.com/aug70/openshift-sails-starter
If you follow the instructions to setup a OpenShift cartridge and merge with this repo, you can deploy it on OpenShift.
Couple important points;
OpenShift package.json file is different!
You would want to use forever when running application and your start script should be something like
"start": "./node_modules/forever/bin/forever -l ~/app-root/logs/forever.log --append --pidFile ~/app-root/logs/forever.pid start app.js --prod"
If you happen to use mongodb, your connections.js file mongodb entry would be
"url : process.env.OPENSHIFT_MONGODB_DB_URL + process.env.OPENSHIFT_GEAR_NAME "
Solution is based on Sails.js version 0.11.0

Issues installing MEAN stack

I have been trying to install the MEAN stack using the following tutorial:
http://www.bossable.com/303/install-mean-stack/#comment-1526
I am using webstorm and MongoDB.
However I have been unsuccessful and I keep getting errors. Everytime I connect to localhost:3000 I get the following error:
C:\meanproject>grunt
Running "jshint:all" (jshint) task
>> 55 files lint free.
Running "csslint:all" (csslint) task
>> 2 files lint free.
Running "concurrent:default" (concurrent) task
Running "nodemon:dev" (nodemon) task
Running "watch" task
Waiting...
[nodemon] v1.2.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: app/views/**/*.* gruntfile.js server.js config/**/*.js app/*
*/*.js
[nodemon] starting `node --debug server.js`
Debugger listening on port 5858
Application loaded using the "development" environment configuration
{ [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }
js-bson: Failed to load c++ bson extension, using pure JS version
{ [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }
js-bson: Failed to load c++ bson extension, using pure JS version
MEAN.JS application started on port 3000
C:\meanproject\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection
\base.js:246
throw message;
^
Error: Error setting TTL index on collection : sessions
at C:\meanproject\node_modules\connect-mongo\lib\connect-mongo.js:169:23
at C:\meanproject\node_modules\mongoose\node_modules\mongodb\lib\mongodb\db.
js:1499:46
at C:\meanproject\node_modules\mongoose\node_modules\mongodb\lib\mongodb\db.
js:1632:20
at C:\meanproject\node_modules\mongoose\node_modules\mongodb\lib\mongodb\cur
sor.js:170:22
at C:\meanproject\node_modules\mongoose\node_modules\mongodb\lib\mongodb\cur
sor.js:714:39
at Cursor.close (C:\meanproject\node_modules\mongoose\node_modules\mongodb\l
ib\mongodb\cursor.js:1009:5)
at commandHandler (C:\meanproject\node_modules\mongoose\node_modules\mongodb
\lib\mongodb\cursor.js:714:21)
at C:\meanproject\node_modules\mongoose\node_modules\mongodb\lib\mongodb\db.
js:1905:9
at Server.Base._callHandler (C:\meanproject\node_modules\mongoose\node_modul
es\mongodb\lib\mongodb\connection\base.js:453:41)
at C:\meanproject\node_modules\mongoose\node_modules\mongodb\lib\mongodb\con
nection\server.js:488:18
at MongoReply.parseBody (C:\meanproject\node_modules\mongoose\node_modules\m
ongodb\lib\mongodb\responses\mongo_reply.js:68:5)
at null.<anonymous> (C:\meanproject\node_modules\mongoose\node_modules\mongo
db\lib\mongodb\connection\server.js:446:20)
at emit (events.js:107:17)
at null.<anonymous> (C:\meanproject\node_modules\mongoose\node_modules\mongo
db\lib\mongodb\connection\connection_pool.js:207:13)
at emit (events.js:110:17)
at Socket.<anonymous> (C:\meanproject\node_modules\mongoose\node_modules\mon
godb\lib\mongodb\connection\connection.js:440:22)
[nodemon] app crashed - waiting for file changes before starting...
How would I go about solving this?
You need to run the mongodb.exe file first. After successfully starting mongodb, you need to navigate into your project folder and run 'grunt'. If it shows you a error list of modules not found, you need to install those modules globally with npm. That will solve the problem for you. However, please note that bossable.com tutorial is for 0.3 mean stack boiler plate. They have upgraded their version to 0.4.1 now. Follow the Meanjs documentation
for latest information.

Categories

Resources