This article mainly shares with you the relevant content on the process of deploying project using forever and pm2. It is shared for your reference and learning. Let’s take a look at the detailed introduction below:
1. forever
Forever can keep the project running when the cmd or ssh connection is disconnected, and can automatically restart when the project crashes.
- Install
npm install -g forever
- forever's help manual
forever --help
- Start the project with forever
forever start
- Stop project using forever
forever stop
- List all projects managed by forever
forever list
- Monitor files in the project and restart the project when there is any change in the file
forever -w start
2. pm2
- Install pm2
npm install -g pm2
- run
pm2 start
- Check the running status
pm2 list
- Track the operation of resources
pm2 monit
- View log
pm2 logs
- Restart the app
pm2 restart appId
- Stop application
pm2 stop
- Enable API access
pm2 web
Predefined run configuration file
We can predefined a configuration file and then formulate and run this configuration file. For example, we define a file, the content is as follows
{ "apps": [ { "name": "ANodeBlog", "script": "bin/www", "watch": "../", "log_date_format": "YYYY-MM-DD HH:mm Z" } ] }
Thenpm2 start
pm2 vs. forever
Feature | Forever | PM2 |
---|---|---|
Keep Alive | ✔ | ✔ |
Coffeescript | ✔ | |
Log aggregation | ✔ | |
API | ✔ | |
Terminal monitoring | ✔ | |
Clustering | ✔ | |
JSON configuration | ✔ |
Summarize
The above is the entire content of this article. I hope the content of this article will be of some help to your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support.