SoFunction
Updated on 2025-03-02

Deploy the project process with forever and pm2

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.

  • Installnpm install -g forever
  • forever's help manualforever --help
  • Start the project with forever forever start
  • Stop project using foreverforever stop
  • List all projects managed by foreverforever list
  • Monitor files in the project and restart the project when there is any change in the fileforever -w start

2. pm2

  • Install pm2npm install -g pm2
  • runpm2 start
  • Check the running statuspm2 list
  • Track the operation of resourcespm2 monit
  • View logpm2 logs
  • Restart the apppm2 restart appId
  • Stop applicationpm2 stop
  • Enable API accesspm2 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.