The installation of the node environment will not be repeated here.There are many tutorials online,It's also very simple.

This article is to use pm2 to achieve automatic restart of nodejs.

What is pm2?As introduced on the official website,pm2 is advanced under nodejs,Production process manager.Such as performance monitoring,Automatic restart, load balancing, and more.

More tutorials on pm2,Please go to pm2 official documentation

1. Make sure node is installed

2. Install pm2

npm install pm2 -g

3. Start the server file using pm2

* Please change the address after start to your own file address

pm2 start /api/server.js --name="nodeserver"

4.Set pm2 to boot

pm2 startup

5. Next, you can experiment.Restart system

shutdown -r now

After the system restarts successfully,You will find that the interface is still accessible

pm2 list #View progress
pm2 stop/reload/restart/delete all #Stop/reload/restart/delete all processes
pm2 stop/reload/restart/delete 0 #stop/reload/restart/delete
pm2 logs [--raw] #Show logs for all processes
pm2 flush #Empty all log files
pm2 reloadlogs #Reload all logs
  • Previous Python button click to close window implementation
  • Next Binding method and unbound method instance analysis of Python class