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

前端 未结 26 1080
隐瞒了意图╮
隐瞒了意图╮ 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:22

    If you are using pm2, you can use it with autorestart set to false:

    $ pm2 ecosystem

    This will generate a sample ecosystem.config.js:

    module.exports = {
      apps: [
        {
          script: './scripts/companies.js',
          autorestart: false,
        },
        {
          script: './scripts/domains.js',
          autorestart: false,
        },
        {
          script: './scripts/technologies.js',
          autorestart: false,
        },
      ],
    }
    

    $ pm2 start ecosystem.config.js

提交回复
热议问题