简体   繁体   English

使用 pm2 与 npm 运行

[英]Use of pm2 with npm run

I havea react frontendapp for which I defined a number of build and run tasks in package.json as shown in the following snippet:我有一个反应前端应用程序,我在 package.json 中定义了许多构建和运行任务,如下面的片段所示:

 "scripts": {
    "start": "env-cmd -f .env.dev react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "build:dev": "env-cmd -f .env.dev npm run build",
    "build:test": "env-cmd -f .env.test npm run build",
    "build:prep": "env-cmd -f .env.prep npm run build",
    "build:prod": "env-cmd -f .env.prod npm run build",
    "start-dev-server": "env-cmd -f .env.dev node server/server.js",
    "start-test-server": "env-cmd -f .env.test node server/server.js",
    "start-prep-server": "env-cmd -f .env.prep node server/server.js",
    "start-server": "env-cmd -f .env.prod node server/server.js"
  },

My goal is to run the app by using the pm2 tool based on a run configuration which should execute "npm run start-server".我的目标是使用基于运行配置的 pm2 工具来运行应用程序,该运行配置应该执行“npm run start-server”。 This execution should internaly run the last line in the above snippet which is "env-cmd -f.env.prod node server/server.js"此执行应在内部运行上述代码段中的最后一行,即“env-cmd -f.env.prod node server/server.js”

I wrote a pm2 config file, namely my_config.json, for to realizing above sketched scenario as follows:我编写了一个 pm2 配置文件,即 my_config.json,以实现上述草图场景如下:

my_config.json: my_config.json:

{
  "apps": [
    {
      "name": "ReactFrontEndApp",
      "script": "npm",
      "args": "run start-server"
    }
  ]
}

Finally, I issue the following command in the command console:最后,我在命令控制台中发出以下命令:

pm2 start my_config.json

When above pm2 command is issued my application is listed under pm2 list command output.发出上述 pm2 命令时,我的应用程序列在 pm2 list 命令 output 下。 Nevertheless, the pm2 tool also starts popping up command-consoles one after another without an end (the previos one fades away and then the next one appears).尽管如此,pm2 工具也开始一个接一个地弹出命令控制台,没有结束(上一个消失,然后出现下一个)。 I tested my application at https://localhost:3000 in the browser meanwhile but the browser does not bring anything my app at all (ie not found).同时,我在浏览器中的 https://localhost:3000 测试了我的应用程序,但浏览器根本没有给我的应用程序带来任何东西(即未找到)。 As a consequence, I have to stop my application by using pm2 stop command.因此,我必须使用 pm2 stop 命令停止我的应用程序。

QUESTION: Is there something I might be missing in the my_config.json file, which might be causing this successive command console opennings?问题: my_config.json 文件中是否有我可能遗漏的东西,这可能导致这个连续的命令控制台打开? What could be wrong?有什么问题?

I guess that your server fail to load somehow, maybe pm2 change relevant environment variables.我猜您的服务器无法以某种方式加载,也许 pm2 更改了相关的环境变量。

what is the output of pm2 logs 0 ? pm2 pm2 logs 0的 output 是什么? what happened when you run npm run start-server manually?手动运行npm run start-server时发生了什么? what happened when run pm2 start npm -- run start-server manually?运行pm2 start npm -- run start-server时发生了什么?

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

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