Restart Node.js server programmatically

后端 未结 2 1313
生来不讨喜
生来不讨喜 2021-01-03 23:53

How to restart Node.js server from code? For example, if using expressjs framework,

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


        
2条回答
  •  梦毁少年i
    2021-01-04 00:11

    By combining npm restart and child_process.exec() it appears possible to restart the server programmatically. And since it allows for several scripts to be run for stopping, restarting, and starting this option would work even for multi-process servers or otherwise complex servers where simply calling process.exit() isn't viable.

提交回复
热议问题