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

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

    UPDATE - As mentioned in one of the answers below, PM2 has some really nice functionality missing from forever. Consider using it.

    Original Answer

    Use nohup:

    nohup node server.js &
    

    EDIT I wanted to add that the accepted answer is really the way to go. I'm using forever on instances that need to stay up. I like to do npm install -g forever so it's in the node path and then just do forever start server.js

提交回复
热议问题