pm2 publishes the node configuration file ecosystem.json

background

Recently, a node+koa+vue project was built to use pm2 release
Here is a simple record
Create a new file at the root
ecosystem.json

{
  "apps": [
    {
      "name": "ant-help-center",
      "script": "./bin/www", //Startup script
      "env": {
        "COMMON_VARIABLE": "true"
      },
      // Test server
      "env_development": {
        "NODE_ENV": "development",
        "PORT": 8087
      },
      // production environment
      "env_production": {
        "NODE_ENV": "production",
        "PORT": 8087
      }
    }
  ],
  "deploy": {
    // production environment
    "production": {
      "user": "root", //username on Nginx server
      "host": ["xxx.xxx.xxx.xxx"], // server address
      "port": "22",
      "ref": "origin/master", //Pull code from specified branch
      "repo": "git@gitee.com:xxx/xxxx.git", // Use
      "path": "/www/website/production", //Publish to the directory specified by the server
      "ssh_options": "StrictHostKeyChecking=no",
      //Build in release
      "post-deploy":
        "npm install && pm2 startOrRestart ecosystem.json --env production",
      "env": {
        "NODE_ENV": "production"
      }
    },
    // testing environment
    "development": {
      "user": "root", //username on Nginx server
      "host": ["xxx.xxx.xxx.xxx"], // server address
      "port": "22",
      "ref": "origin/master", //Pull code from specified branch
      "repo": "git@gitee.com:xxx/xxxx.git",
      "path": "/www/website/development", //Publish to the directory specified by the server
      "ssh_options": "StrictHostKeyChecking=no",
      //Build in release
      "post-deploy":
        "npm install && pm2 startOrRestart ecosystem.json --env development",
      "env": {
        "NODE_ENV": "development"
      }
    }
  }
}

Note:
One: the address of git ssh to be used for the repo parameter

Two: you need permission to create path directory on the server first

Create corresponding directory / www/website/development
 Get write permission of development Directory

Release

Right click the local folder to open git bash
Implement Article 1 after success

 pm2 deploy ecosystem.json production setup

implement

 pm2 deploy ecosystem.json production

Note:
One: ssh public key must be added to Baidu
2. To publish, you need to enter the password of the server

Last

Use ip address plus project port number to access, if not successful
You can enter the current folder of the project to execute the startup command
such as

node ./bin/www // Check whether the error is reported and check the error

Other points to be noted
One: the port of the node project should be set in the cloud service provider, the white list of the security group, or it cannot be accessed
2. Check whether the port is occupied

About me

You can scan and add the wechat below and note Soul plus exchange group, give me opinions, exchange and learn.

If I can help you, send me a little star

Reprint please contact the author!

Tags: node.js git JSON Nginx npm

Posted on Sun, 10 Nov 2019 14:13:59 -0800 by q1234ask