Can pm2 run an 'npm start' script

前端 未结 17 1154
心在旅途
心在旅途 2020-12-04 04:45

Is there a way for pm2 to run an npm start script or do you just have to run pm2 start app.js

So in development

npm start

相关标签:
17条回答
  • 2020-12-04 05:12

    It's working fine on CentOS 7

    PM2 version 4.2.1

    let's take two scenarios:

    1. npm start //server.js

    pm2 start "npm -- start" --name myMainFile
    

    2. npm run main //main.js

    pm2 start "npm -- run main" --name myMainFile
    
    0 讨论(0)
  • 2020-12-04 05:16

    you need to provide app name here like myapp

    pm2 start npm --name {appName} -- run {script name}

    you can check it by

    pm2 list

    you can also add time

    pm2 restart "id" --log-date-format 'DD-MM HH:mm:ss.SSS' or pm2 restart "id" --time

    you can check logs by

    pm2 log "id" or pm2 log "appName"

    to get logs for all app

    pm2 logs

    0 讨论(0)
  • 2020-12-04 05:16

    To run PM2 with npm start method and to give it a name, run this,
    pm2 start npm --name "your_app_name" -- start

    To run it by passing date-format for logs,
    pm2 start npm --name "your_name" --log-date-format 'DD-MM HH:mm:ss.SSS' -- start

    0 讨论(0)
  • 2020-12-04 05:17

    If you use PM2 via node modules instead of globally, you'll need to set interpreter: 'none' in order for the above solutions to work. Related docs here.

    In ecosystem.config.js:

      apps: [
        {
          name: 'myApp',
          script: 'yarn',
          args: 'start',
          interpreter: 'none',
        },
      ],
    
    0 讨论(0)
  • 2020-12-04 05:19

    Don't forget the space before start

    pm2 start npm --[space]start
    

    so the correct command is:

    pm2 start npm -- start
    
    0 讨论(0)
  • 2020-12-04 05:20

    PM2 now supports npm start:

    pm2 start npm -- start
    

    To assign a name to the PM2 process, use the --name option:

    pm2 start npm --name "app name" -- start
    
    0 讨论(0)
提交回复
热议问题