Reference Address: http://www.jianshu.com/p/43525232b03b
Reference Address: http://blog.csdn.net/leo_perfect/article/details/53690768
Normally start a project, use the command NPM start to launch a project, but if the program encounters a serious bug, will automatically exit, and do not know how to restart the project, PM2 can solve the problem
In a folder, create a app.js
Enter the following text in App.js
var http = require (' http '); http.createserver(function (req, res) { Res.writehead (
Res.end (' Hello world\n ');}). Listen (1337, "127.0.0.1"); Console.log (' Server running at http://127.0.0.1:1337/');
and execute the command to install the dependent package
NPM Install HTTP
Global Installation PM2
NPM install-g PM2
Executes the command at the location of the code, and after the command executes, App.js runs in the background.
When we start a task, we can also specify how much of the task
We can view the running tasks through the PM2 list
You can also restart all tasks by PM2 restart all
Stop all Tasks by command PM2 stop all
$ PM2 Start app.js-i 4 # Background Run PM2, start 4 app.js
# You can also pass the ' max ' argument to start
# The correct number of processes depends on the number of cores in the CPU
$ pm2 Start app.js--name My-api # naming process
$ PM2 List # shows all process states
$ PM2 Monit # Monitor All Processes
$ PM2 Logs # show all process logs
$ pm2 Stop 0 # stops the specified process
$ pm2 Stop all # stops all processes
$ pm2 Restart 0 # Restart the specified process
$ pm2 Restart all # restart all processes
$ pm2 Delete 0 # kills the specified process
$ pm2 Delete all # kills all processes
$ pm2 Reload All # 0 seconds Downtime Heavy process (for networked process)
$ PM2 Startup # generates INIT script to keep the process alive
$ PM2 Web # runs the robust computer API endpoint (http://localhost:9615)
Nodejs PM2 Use