명령어들

sudo touch pm2.json && sudo chown $USER pm2.json && sudo chmod 755 pm2.json

sudo pm2 start pm2.json
sudo pm2 list
sudo pm2 log 0
sudo pm2 stop 0
sudo pm2 delete 0
sudo pm2 start 0
sudo pm2 restart 0

package.json 예시

{
  ...
  "scripts": {
    "api-start": "ts-node src/index.ts",
    "api-watch": "nodemon src/index.ts",
    "aws-watch": "nodemon -I src/index.ts"
  }
}

1. 빌드하지 않고 바로 실행

pm2.json

{
    "name"  : "fastify:4000",
    "script": "npm",
    "args"  : "run aws-watch",
    "watch" : true,
    "env"   : {
        "PORT_NUMBER": 4000
    },
    "log_date_format": "YYYY-MM-DD HH:mm Z",
    "exec_mode": "fork"
}

2. 빌드 후 실행

pm2-prod.json

{
    "name"  : "fastify-prod:5000",
    "script": "dist/index.js",
    "watch" : true,
    "env"   : {
        "PORT_NUMBER": 5000,
        "NODE_ENV": "production"
    },
    "log_date_format": "YYYY-MM-DD HH:mm Z",
    "exec_mode": "fork"
}