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

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

    You really should try to use screen. It is a bit more complicated than just doing nohup long_running &, but understanding screen once you never come back again.

    Start your screen session at first:

    user@host:~$ screen
    

    Run anything you want:

    wget http://mirror.yandex.ru/centos/4.6/isos/i386/CentOS-4.6-i386-binDVD.iso
    

    Press ctrl+A and then d. Done. Your session keeps going on in background.

    You can list all sessions by screen -ls, and attach to some by screen -r 20673.pts-0.srv command, where 0673.pts-0.srv is an entry list.

    0 讨论(0)
  • 2020-11-22 11:40

    Nohup and screen offer great light solutions to running Node.js in the background. Node.js process manager (PM2) is a handy tool for deployment. Install it with npm globally on your system:

    npm install pm2 -g

    to run a Node.js app as a daemon:

    pm2 start app.js

    You can optionally link it to Keymetrics.io a monitoring SAAS made by Unitech.

    0 讨论(0)
提交回复
热议问题