How does one start a node.js server as a daemon process?

后端 未结 8 1524
余生分开走
余生分开走 2020-11-30 17:41

In Python Twisted, you have the twistd command that helps you with a number of things related to running your application (daemonize it for example).

Ho

8条回答
  •  无人及你
    2020-11-30 18:09

    Forever is answer to your question.

    Install

    $ curl https://npmjs.org/install.sh | sh
    $ npm install forever
    # Or to install as a terminal command everywhere:
    $ npm install -g forever
    

    Usage

    Using Forever from the command line

    $ forever start server.js
    

    Using an instance of Forever from Node.js

    var forever = require('forever');
    
      var child = new forever.Forever('your-filename.js', {
        max: 3,
        silent: true,
        args: []
      });
    
      child.on('exit', this.callback);
      child.start();
    

提交回复
热议问题