First, use forever
forever is a nodejs daemon, completely controlled by the command line. forever monitors nodejs service, and a restart after a service hang.
1, the installation forever
Forever -g install npm
2, start the service
forever Start Service
3, use forever to start js file
Start index.js Forever
4, stop js file
STOP index.js Forever
5, start js file and log file output
Start the -l -o out.log forever.log Forever -e err.log index.js
6, restart js file
index.js restart Forever
7, viewing running processes
forever list
Two, pm2 is a process management tool that you can use to manage your node process, and view node status of the process, of course, also support performance monitoring, process guard, load balancing and other functions
npm install -g pm2
pm2 start app.js // 启动
pm2 start app.js -i max //启动 使用所有CPU核心的集群 pm2 stop app.js // 停止 pm2 stop all // 停止所有 pm2 restart app.js // 重启 pm2 restart all // 重启所有 pm2 delete app.js // 关闭
Three, nodejs comes node.js own service nohub, no need to install other packages.
Cons: Can not query logs and other issues exist, after closing the Terminal Services will close, has been tested like this.
nohup node ***.js &