Website stops working nodejs - node.js

I have website on Ubuntu sever.
I have started process using this command
sudo pm2 start app.js -i 0
it was working fine.Today morning my client message me it's stop working.
I have stoped the node and re-start the process again using same command.
Now I want to know the reason by this happens?
How i can do this to check the issue ?
Thanks

check pm2 logs folder ( PM2_PROCESS_USER_HOME_DIRECTORY/.pm2/logs)
May be server crash and you did't setup pm2 autostart
active pm2 autostart :
pm2 startup ubuntu
pm2 save

Related

Node app crashes after closing the terminal, even using pm2

I'm doing web automation by using Puppeteer with NodeJS. It works fine when I'm logged in to the terminal. I'm using ec2 instance Ubuntu 22 server.
But when I'm exit out of the terminal and then try to perform the task it just loads and loads and do nothing. But when I log in to check the pm2 logs then it starts working again with the terminal open.
When I check pm2 logs I get this error every time.
Error in pm2 logs:
I suppose there is problem with the command you are trying to run the app. Use the following command to run the app via pm2.
npx pm2 start app
For Cpanel Users having this issue
Login to your WHM account, click on the terminal, cd into the directory where your node js application is, then pm2 start .This was how i solved my issue.

Nodejs API doesn't work after reboot centos server

In my centos server, I have an API with node js and I started with pm2. pm2 status is online and It works correctly. but when server reboot, can't connect to the API although pm2 status is online.
I also try start node js like below
pm2 start index.js
pm2 startup
pm2 save
but It does not work until I restart pm2 ..
how can I fix it?
You have to do pm2 resurrect to start an application after "pm2 saving" it:
pm2 resurrect
Then put this command in a script file and configure it to run on server reboot. Read this Q and A for help. Also in this article there are some CentOS specific changes that need to be done.

NodeJS changes not reflected on server

I'm running NodeJS application on CentOS with PM2. Everything works fine.
But I made a query changes in one of the controller file (add new column in SQL query). And then uploaded the project files to server. And then run PM2 restart [app-id].
It's strange that new column was not returned in the api response payload.
Is there anyway to clear cache of PM2? or What is the issue exactly?
Please advise!
For me worked sudo -u nodejs pm2 restart hello
more info:
https://marketplace.digitalocean.com/apps/nodejs#getting-started
Try running the following command.
pm2 stop app_name
pm2 restart app_name
pm2 reload app_name

Getting error when trying to launch node.js app with PM2 Cluster

in an Ubuntu Server, I am unable to run the node.js app in cluster mode using PM2.
The command I use is :
PM2 start server.js --name Server -i max
When I list the PM2 processes, I can see the Server has Error status.
I have tried looking into the log file generated by PM2 but it's empty.
I am however able to run the same server.js without the cluster mode using :
PM2 start server.js --name Server
doing PM2 Kill and starting all the services again was the solution to above issue.
You could also have used pm2 restart Server to restart it
If you use pm2 kill you will just kill all processes, to clean up afterwards i would recommend to use pm2 flush so all logfiles will be reset
I have gone through this same kind of situations but in my case pm2 is showing error status cause of error in my code.
use the below command
pm2 logs
pm2 logs command helped me by showing some hints to check where exactly the error is occured.
if everything works fine then pm2 list will show you the status online.
you can check the ports running by pm2(not only pm2 but all the process) using below command
sudo netstat -tulpn

Start Node JS application when server reboots with pm2

I am trying to use the module pm2 to start my node js app everytime the server boots.
I have used the command pm2 startup ubuntu but each time I restart the server, my application is not running and I have to start it manually again.
Any ideas what is causing this issue?
Make sure you do save your processes:
pm2 start app.js
pm2 startup ubuntu
pm2 save
Once you have started the apps and want to keep them on server reboot
do: pm2 save
Source: https://github.com/Unitech/PM2/blob/master/ADVANCED_README.md#startup-script
Go to your server directory and use the following commands:
pm2 start <your_app_name.js>
pm2 startup ubuntu
pm2 save

Resources