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

前端 未结 14 1078
刺人心
刺人心 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

    nohup node server.js > /dev/null 2>&1 &

    1. nohup means: Do not terminate this process even when the stty is cut off.
    2. > /dev/null means: stdout goes to /dev/null (which is a dummy device that does not record any output).
    3. 2>&1 means: stderr also goes to the stdout (which is already redirected to /dev/null). You may replace &1 with a file path to keep a log of errors, e.g.: 2>/tmp/myLog
    4. & at the end means: run this command as a background task.

提交回复
热议问题