简体   繁体   English

pm2从子目录开始

[英]pm2 start in subdirectory

I have a script in package.json like this. 我在package.json有一个这样的脚本。 To run with npm I would just do it with npm start . 要使用npm运行,我只需使用npm start

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

I am currently trying to setup a pm2 config file for this. 我目前正在尝试为此设置pm2配置文件。 I created a ecosystem.json file. 我创建了一个ecosystem.json文件。 Neither of both of the following work with pm2 ecosystem command. 以下两项均不适用于pm2 ecosystem命令。 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. 请注意,如果我在命令中手动键入cd build && pm2 start main.js ,它会起作用,但这不是我想要的。

First configuration: 第一种配置:

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

Second configuration 第二配置

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

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 点击pm2 ecosystem命令,这将创建一个新文件,名称为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 点击pm2 start ecosystem.config.js

  4. Check the logs using pm2 logs , your app will be started. 使用pm2 logs ,您的应用程序将启动。

Hope this helps you. 希望这对您有所帮助。

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

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