How do I run a node.js app as a background service?

前端 未结 26 1056
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 05:28

Since this post has gotten a lot of attention over the years, I\'ve listed the top solutions per platform at the bottom of this post.


Original post

26条回答
  •  广开言路
    2020-11-22 06:09

    I am simply using the daemon npm module:

    var daemon = require('daemon');
    
    daemon.daemonize({
        stdout: './log.log'
      , stderr: './log.error.log'
      }
    , './node.pid'
    , function (err, pid) {
      if (err) {
        console.log('Error starting daemon: \n', err);
        return process.exit(-1);
      }
      console.log('Daemonized successfully with pid: ' + pid);
    
      // Your Application Code goes here
    });
    

    Lately I'm also using mon(1) from TJ Holowaychuk to start and manage simple node apps.

提交回复
热议问题