Nodejs PM2 Use

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.