Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automatically restart Node scripts when they crash in production?

Tags:

node.js

The forever package appears stale (no commits in over 2 years) and its dependencies are out of date.

like image 425
sunknudsen Avatar asked Sep 14 '25 10:09

sunknudsen


1 Answers

Your solution is PM2. It is a production process manager for Node applications, very easy to use. Installing PM2 with npm and running a simple command like pm2 start app.js you are almost done.

Additionally, you will have some useful tools, like logs and monitoring of your app status.

PM2 running application will be restarted automatically if the application crashes or is killed. Also, you can secure that your app will launch on server reboot, by adding it on system startup with pm2 startup systemd command.

like image 137
dimitris tseggenes Avatar answered Sep 17 '25 03:09

dimitris tseggenes