desmondlee
desmondlee

Reputation: 1703

pm2 start in subdirectory

I have a script in package.json like this. To run with npm I would just do it with npm start.

"scripts": {
    "start": "cd build && node main"
}

I am currently trying to setup a pm2 config file for this. I created a ecosystem.json file. Neither of both of the following work with pm2 ecosystem command. What am I doing it wrong?

Note that it work if i manually type cd build && pm2 start main.js in command but this is not something i want.

First configuration:

{
    "apps": [{
        "name": "my-app",
        "cwd": "build",
        "script": "main.js"
    }]
}

Second configuration

{
    "apps": [
        {
            "name": "my-app",
            "script": "npm",
            "args" : "start"
        }
    ]
}

Upvotes: 2

Views: 7947

Answers (1)

Harshal Yeole
Harshal Yeole

Reputation: 4983

In your code, you are giving the path incorrectly.

Use following instructions:

  1. Hit pm2 ecosystem command, this will create a new file by name ecosystem.config.js

  2. Remove all the code from the file and add the following code.

    module.exports = {
      apps : [
        {
          name      : 'API',
          script    : 'build/main.js',
        }
      ]
    };
    
  3. Hit pm2 start ecosystem.config.js

  4. Check the logs using pm2 logs, your app will be started.

Hope this helps you.

Upvotes: 2

Related Questions