Nodejs API doesn't work after reboot centos server - node.js

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.

Related

Why pm2 is fine, but pm2 logs is not?

I'm using pm2 to keep tracking of what I do on backend with NodeJS. Until yesterday it all worked perfectly fine, but today, even if pm2 server is working fine (i can start the project server and i can navigate), pm2 logs just stopped for no reasons.
Here you can see the version I'm using (i already updated PM2 both on project and local as i find in other answers).
I usually use the command
pm2 start process.json
pm2 restart 0 --watch
pm2 restart 0
And in other prompt instance, for the logs i use
pm2 logs
For some reason PM2 is just tailgating the last 15 lines but it doesn't work real time like it used to do
I didn't find this exact problem on other questions (only questions about pm2 not working at all, but not about pm2 working half way). Any suggestions?
Apparently the version of node and pm2 were the source of the problem. I used this command to run pm2 using the node version explicitly
pm2 start process.json --interpreter=/home/ken/.nvm/v10.15.1/bin/node
This way you force pm2 to use settings for the version of node you've installed in your machine. Now both server and logs works fine.

How to deploy a NodeJS app without root access, so it stays online after server restarts?

I'm trying to deploy my NodeJS app. I tried npm forever and pm2, but I believe that my hoster restarts the server every night because my app is always offline the next day.
The thing is, that I have a shared hosting server on A2hosting and don't have root access, so these sudo commands don't work here... except you know how I can change that, haha...
I don't know what infos I need to provide for you to help me... so if you need to know something, tell me please!
Thank you so much!
I've used pm2 to do that.
npm install -g pm2
then you run the following command to ensure pm2 will run on startup:
pm2 startup
It will show you the command you have to run.
Finally, you initiate the process:
pm2 start server.js --name <service-name>
Freeze your process list:
pm2 save
More details on pm2 documentation: https://github.com/Unitech/pm2

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

Website stops working nodejs

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

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