content
- First acquaintance of pm2
-
- Create file directory
- Install express start local service (start two express services)
- pm2 installation
- Basic commands for pm2
-
- run node with pm2
- Use pm2 logs to view the started node services
- pm2 list to view the enabled services
- pm2 stop id (0 or 1, etc.) shuts down the service
- pm2 restart id restarts the service
- pm2 start index --watch to monitor node services in real time
- stop all services pm2 stop all
- delete service order
First acquaintance of pm2
- effect:
- The role of pm2 is the application process management of node, which can simplify the operation management of node (such as monitoring, restarting services, etc.)
Create file directory
- mkdir XX creates a file directory
- cd XX to enter the file
Install express start local service (start two express services)
yarn add express -S
index service 1
yarn add express -S
npm init -y
- run command
node index.js
const express = require('express')
const app = express()
app.get('/index', (req, res) => {
res.json({
data: [11]
})
})
app.listen(9999, () => {
console.log("success server index2 http://localhost:9999/index");
})
index2 service 2
yarn add express -S
npm init -y
- run command
node index2.js
const express = require("express")
const app = express()
app.get('/index2', (req, res) => {
res.json({
data: [111, 222]
})
})
app.listen(8888, () => {
console.log("success server index2 http://localhost:8888/index2");
})
// 开一个服务 端口为3333
+effect
pm2 installation
- Install
npm i pm2 -g
- View installation
pm2 -v
- Display the version number successfully
Basic commands for pm2
run node with pm2
pm2 start app.js
- Note: app/app.js
Use pm2 logs to view the started node services
pm2 logs
- Effect
pm2 list to view the enabled services
pm2 list
- Effect
pm2 stop id (0 or 1, etc.) shuts down the service
pm2 stop 0
- Effect
pm2 restart id restarts the service
pm2 restart 0
- Effect
pm2 start index --watch to monitor node services in real time
pm2 start index --watch
- Effect
- That is, when you modify the data returned by node, you do not need to restart the service, just refresh the browser.
stop all services pm2 stop all
pm2 stop all
delete service order
pm2 delete app_name | app_id
delete a servicepm2 delete all
delete all