How to run Node.js as a background process and never die?

前端 未结 14 946
刺人心
刺人心 2020-11-22 10:59

I connect to the linux server via putty SSH. I tried to run it as a background process like this:

$ node server.js &

However, after 2.5

14条回答
  •  太阳男子
    2020-11-22 11:21

    Simple solution (if you are not interested in coming back to the process, just want it to keep running):

    nohup node server.js &
    

    There's also the jobs command to see an indexed list of those backgrounded processes. And you can kill a backgrounded process by running kill %1 or kill %2 with the number being the index of the process.

    Powerful solution (allows you to reconnect to the process if it is interactive):

    screen
    

    You can then detach by pressing Ctrl+a+d and then attach back by running screen -r

    Also consider the newer alternative to screen, tmux.

提交回复
热议问题