How to use pm2 start npm in a specific directory?
Asked Answered
W

1

6

Is there a CLI tag for running pm2 start npm -- start in a specific directory? I looked around but could not find an answer.

On the other hand, when I run pm2 without npm, I can specify which directory I want to run pm2 in. For example:

pm2 start /opt/www/myapp/index.js

Is there any way to add a path tag to the pm2 start npm -- start command?

Whiggism answered 11/8, 2022 at 16:11 Comment(0)
D
6

You can use something like this:

cd /directory/of/my/app ; pm2 start npm -- start

You can also write an ecosystem file to parameter you app:

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

To generate an empty ecosystem file:

pm2 init simple

this will generate a file named ecosystem.config.js that you can rename.

Then to start application:

pm2 start ecosystem.config.js

ecosystem doc: https://pm2.keymetrics.io/docs/usage/application-declaration/

Destination answered 11/8, 2022 at 17:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.