简体   繁体   English

如何在特定目录下使用pm2启动npm?

[英]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?是否有用于运行pm2 start npm -- start在特定目录中启动的 CLI 标签? 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:另一方面,当我在没有npm 的情况下运行 pm2 时,我可以指定要在哪个目录中运行 pm2。例如:

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

Is there any way to add a path tag to the pm2 start npm -- start command?有什么方法可以在pm2 start npm -- start命令中添加路径标签吗?

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.这将生成一个名为ecosystem.config.js .config.js 的文件,您可以重命名该文件。

Then to start application:然后开始应用:

pm2 start ecosystem.config.js

ecosystem doc: https://pm2.keymetrics.io/docs/usage/application-declaration/生态系统文档: https://pm2.keymetrics.io/docs/usage/application-declaration/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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