我试图在Windows 2016上运行多古龙,Node.js版本为12.14.0,通过PM2 on IIS10运行。我正在使用PM2,以便在服务器重新启动后重新启动应用程序。我不得不承认,今天是我第一次尝试用Node.js做任何事情,所以请容忍我。
这是常跑,通过在Docusaurus目录中调用npm run start
。在测试Node.js以及“Hello”应用程序是否会重新启动服务器时,我使用的是PM2文档中建议的ecosystem.config.js
。这就调用了像这样的javascript文件。
module.exports = {
apps: [
{
name: "HelloWorld",
script: "apps\\hello_world.js",
instances: 1
}
]
}
这很好,但是我没有找到任何关于如何从这个文件运行npm start
的文档(尽管我尝试过调用一个单独的批处理文件,它也不起作用)。然后我看到了这里,我可以调用一个JSON文件来记录进一步的选项。
JSON配置文件:
{
"apps": [
{
"name": "docs",
"cwd": "apps\\docs",
"script": "npm",
"args": "start"
},
{
"name": "HelloWorld",
"script": "apps\\hello_world.js"
}
]
}
“HelloWorld”脚本启动,但不是docs应用程序。
pm2报告提供了以下输出:
PM2 | 2020-01-07T17:54:20: PM2 log: App [docs:0] exited with code [1] via signal [SIGINT]
PM2 | 2020-01-07T17:54:20: PM2 log: App [docs:0] starting in -fork mode-
PM2 | 2020-01-07T17:54:20: PM2 log: App [docs:0] online
PM2 | 2020-01-07T17:54:21: PM2 log: App [docs:0] exited with code [1] via signal [SIGINT]
PM2 | 2020-01-07T17:54:21: PM2 log: App [docs:0] starting in -fork mode-
PM2 | 2020-01-07T17:54:21: PM2 log: App [docs:0] online
PM2 | 2020-01-07T17:54:21: PM2 log: App [docs:0] exited with code [1] via signal [SIGINT]
PM2 | 2020-01-07T17:54:21: PM2 log: App [docs:0] starting in -fork mode-
PM2 | 2020-01-07T17:54:21: PM2 log: App [docs:0] online
PM2 | 2020-01-07T17:54:21: PM2 log: App [docs:0] exited with code [1] via signal [SIGINT]
PM2 | 2020-01-07T17:54:21: PM2 log: App [docs:0] starting in -fork mode-
PM2 | 2020-01-07T17:54:21: PM2 log: App [docs:0] online
PM2 | 2020-01-07T17:54:22: PM2 log: App [docs:0] exited with code [1] via signal [SIGINT]
PM2 | 2020-01-07T17:54:22: PM2 log: App [docs:0] starting in -fork mode-
PM2 | 2020-01-07T17:54:22: PM2 log: App [docs:0] online
PM2 | 2020-01-07T17:54:22: PM2 log: App [docs:0] exited with code [1] via signal [SIGINT]
PM2 | 2020-01-07T17:54:22: PM2 log: App [docs:0] starting in -fork mode-
PM2 | 2020-01-07T17:54:22: PM2 log: App [docs:0] online
PM2 | 2020-01-07T17:54:22: PM2 log: App [docs:0] exited with code [1] via signal [SIGINT]
PM2 | 2020-01-07T17:54:22: PM2 log: Script C:\PROGRAM FILES\NODEJS\NPM.CMD had too many unstable restarts (16). Stopped. "errored"
这让我想到了这在GitHub上的问题。然而,在这些问题上似乎没有太多的活动,而且也有历史上的事件。
我认为PM2可能做错了什么,或者有问题,因为我也不能通过PM2命令行启动docs。
C:\Node JS\apps\docs>pm2 start npm --name "docs" -- start
有没有人对我如何让这件事起作用有什么想法,或者有没有试过做类似的事?我会满足于以下几个问题:
如果我胡言乱语的话。
编辑:
pm2 start ecosystem.json --only docs
输出
C:\Node JS>pm2 start ecosystem.json --only docs
[PM2][WARN] Applications docs not running, starting...
[PM2][ERROR] Process failed to launch EPERM: operation not permitted, open 'C:\etc\.pm2\logs\docs-out.log'
它引用的日志为空。docs-error.log
重复重复相同的错误,但从昨晚开始就没有更新过。它可能是通过我在JSON文件中尝试不同的语法创建的,但无论如何都是发布的。
SyntaxError: Unexpected token ':'
at Module._compile (internal/modules/cjs/loader.js:895:18)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Object.<anonymous> (C:\Users\user\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainerFork.js:27:21)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
C:\PROGRAM FILES\NODEJS\NPM.CMD:1
:: Created by npm, please don't edit manually.
发布于 2021-08-11 20:33:21
这是一个更清晰的最新答案:
package.json文件(包含下面的示例脚本)
"scripts": {
"start": "concurrently npm:server npm:dev",
"dev": "react-scripts start",
"build": "node ./scripts/build.js",
"eject": "react-scripts eject",
"lint": "eslint src server",
"shivkumarscript": "ts-node -T -P server/tsconfig.json server/index.ts"
}
假设我们希望使用pm2实用程序运行名为“shivkumarscript”的脚本。因此,我们的pm2配置文件应该如下所示,包含“脚本”键,值为“npm”,“args”键,值为“run”。在我们的例子中,脚本名是“shivkumarscript”。
ecosystem.config.json文件
module.exports = {
apps: [
{
name: "NodeServer",
script: "npm",
automation: false,
args: "run shivkumarscript",
env: {
NODE_ENV: "development"
},
env_production: {
NODE_ENV: "production"
}
}
]
}
假设您已经在您的计算机上安装了Node.js、NPM和PM2。然后,下面应该是通过pm2启动应用程序的命令,后者将运行npm脚本(应用程序的package.json文件中提到的命令行):
生产环境:
pm2 start ecosystem.config.js --env production --only NodeServer
关于发展环境:
pm2 start ecosystem.config.js --only NodeServer
...And Boooom!伙计们
https://stackoverflow.com/questions/59634041
复制相似问题