Project to Vue.js+layui as the front-end development technology stack, need to have an online environment for project members to view the effect in real time, can not be webpack every time after packaging release to see the effect! Just start with the npm run dev command hot start, but after the shell command window exits, the hot start will fail! Not the computer has been not closed, after the consideration of the way to run the hot-start command, the idea of a good process management tool, is PM2.
1. What is PM2?
Daily development needs to start a node project, need to use NPM run ..., if the terminal is turned off, the program will automatically stop, sometimes a few projects run together, several terminals open, the individual is not very like, there is an artifact can be resolved: PM2. PM2 is a process manager for a node app with load Balancing. When you are going to take your standalone code all the CPUs on the server and make sure that the process is always alive, 0 seconds of overloading, PM2 is perfect. It's great for IaaS architecture, but don't use it for PAAs scenarios.
2. Global Installation
NPM install-g PM2
3. Daily use
Because of the blossoming of node, there are many ways to start a website. Here's a: npm run Dev for example:
First look at the project's Package.json file:
"Scripts": { "dev": "Node Build/dev-server.js--env=local", "Start": "Node Build/dev-server.js--env =local ", " Build ":" Node Build/build.js--env=publish ", " build-local ":" Node Build/build.js " },
NPM Run Dev is actually running the node script file: Dev-server.js,
Can start with PM2: PM2 start build/dev-server.js, you can give this process a name you can remember to understand: PM2 start build/dev-server.js--name xxx, (XXX is the name you define)
If your node project configuration file and the above code is not the same,,, MO, pm2 there is a way to start (personally feel that this is a universal startup method):
PM2 start NPM--run XXX
With her alternative: npm run dev, it can be written as: PM2 start NPM-run Dev, project startup:
Although the project started, but the name is not what I want (I need a name that I can remember, and a project is a unique name), this time can be used:
PM2 start NPM--watch--name webpack-agent-run Dev
OK PM2 's routine also has some common directives, such as:
To view the startup items you have used:
PM2 List
Restart:
PM2 Restart XXX (project name)
Stop it:
PM2 Stop XXX (project name)
Delete
PM2 Delete XXX (project name)
If you do not remember, directly in the console input: PM2, the console will give the daily instructions, and the instructions will be given the corresponding instructions:
This article turns from https://www.cnblogs.com/wangrongxiang/p/7909885.html
Use PM2 to build an online vue.js development environment (Hot start daemon mode)