Reboot Node.js software server

How to reload Node.js server from code? For example, if you use the expressjs framework,

app.get('/restart', function (req, res, next) { //Code to restart a server }) 

I want to restart the server from an application like this, without the need for a console, etc. How to do it?

+7
source share
1 answer

I use forever to run and monitor the application. So the restart function:

 app.get('/restart', function (req, res, next) { process.exit(1); }); 

After server shutdown, forever restart the service.

Prefixes:

  Express server listening on port 3000 in development mode
 error: Forever detected script exited with code: 1
 error: Forever restarting script for 2 time
 Express server listening on port 3000 in development mode
+13
source share

All Articles