posted by 지니우스 2017. 6. 26. 14:21

참고: https://stackoverflow.com/questions/4797050/how-to-run-process-as-background-and-never-die



1안) nohup을 사용. 출력을 /dev/null 로 내보내기.


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.


2안) pm2 패키지 설치해서 사용하기.


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