简体   繁体   中英

How to use pm2 start npm in a specific directory?

Is there a CLI tag for running pm2 start npm -- start in a specific directory? I looked around but could 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?

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM