Load node JS Web app so slow in VPS with pm2 - node.js

Im using pm2 start app.js --watch but it's very slow to reload my web app. It always must to refresh the browser for get the page fast. What should i do?

Related

how to serve build folder with pm2

I am trying to serve my node.js and react application with pm2 including loading data from mongoDB.
So far I can serve the build with serve -s build -l 3001 i am using port 3001 for the front end.
And pm2 start server.js for the backend which runs on port 3000. This runs and loads data successfully.
However, instead of using pm2 start server.js I want to be able to run pm2 serve build/ 3000 with my app name however when I do this my web page turns blank, all responses are 200 and there is nothing in the logs.
I have also checked online and searched many resources all result back to exactly what i am currently doing.
I am using npm run build to create my build folder.
Does anyone know a way to successfully serve your react build directory with pm2 ?
Thank you!

PM2 can not reload application

My application is working very well. I`m using PM2 clustering mode in this application and I reloaded it to much without any error. But now when I wanna reload my app, it does not work and shows me this error :
This is my reloading command:
pm2 reload myapp

PM2 not showing Express app in browser

I am using PM2 in my Express app for process management and load balancing. I have just installed the PM2 and given the command pm2 start bin/www
this command works in command prompt, it is showing the result like this:
This is fine now I am opening the web browser and accessing the application as usual localhost:3000 but it is not opening the application its is showing ok in the browser.
What could be the possible reason? Please help. Thanks.
I got the solution. We know when we create an app using Express (Express generator) it creates all the folder and places app.js file in the root folder. For some reason, I kept the app.js file inside a folder and changed its path in bin/www file. It was working perfectly when I was running npm start but with PM2 it was now opening the application in the browser. So I again placed the app.js file in the root folder and now it is working fine.

Disable livereload with Yeoman angular web app

I have a Yeoman web app up and running. It fails to retrieve livereload.js and can take up 21s before timing out and the page then goes on to load.
I don't even need the livereload functionality. This is a web app that is finished with development.
I use forever to start the web app. I navigate to the root folder of my app which contains my Gruntfile.js. I then run the command - forever start /usr/local/bin/grunt
What do I need to do to disable this livereload functionality?
You can disable running livereload server from the grunt file. However, that will still load the livereload js file in website footer and result in very slow page loads.
The reload script is being added from the server side. Edit the file server/config/express.js and comment out the line:
app.use(require('connect-livereload')());
Note: You seem to have bigger problems as well. You said, the site has completed development, but livereload works which is possible only when the server is running in development mode(unless you have edited Gruntfile to that effect). What you need is grunt serve:dist instead of simple grunt serve. Running the server in dev environment is a security as well as performance problem.
PS: I started with a similar set up but found later that sometimes the app.js will throw an error while grunt will continue running. This will put forever useless. You shall need the grunt-forever npm module to make sure forever is monitoring the right file.

Combine Yeoman Server and Node Supervisor

I'm using Yeoman to develop the frontend html app (backbone and bootstrap) and would like to use the same folder for backend development for the api (node, express, mongodb).
What I would like to do is to have the browser refreshed no matter what file was changed on frontend or backend.
What I'm doing now is:
For Yeoman I'm using the "yeoman server" that would refresh the browser every time I change something in the app folder.
I'm using the node supervisor module and executing the "supervisor server.js" for automatically kill the server and relaunch the node server if file is changed on the backend.
I'd like to avoid this as I need to run the yeoman and node server on different ports.
Is there a way to force autoreload of the browser with node supervisor or use the yeoman server as a classic node server?
You should be able to force the browser to reload with command grunt reload. Just childProcess.exec or childProcess.spawn the command.

Resources