我正在尝试通过IIS10上的PM2在带有Node.js 12.14.0版的Windows Server 2016上运行Docusaurus。我正在使用PM2,因此可以在服务器重新启动后重新启动应用程序。我现在必须承认,今天是我第一次尝试使用Node.js做任何事情,所以请多多包涵。
通过在Docusaurus目录中调用npm run start
来usually run。在测试Node.js以及是否在服务器重新启动时启动“ Hello World”应用程序时,我正在使用PM2文档中建议的ecosystem.config.js
。这样称为javascript文件。
module.exports = {
apps: [
{
name: "HelloWorld",
script: "apps\\hello_world.js",
instances: 1
}
]
}
这很好用,但是我找不到从该文件运行npm start
的任何文档(尽管我确实尝试调用一个单独的批处理文件,该文件也不起作用)。然后我看到here可以调用记录了更多选项的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上的this问题。尽管如此,关于该问题的活动似乎并不多,而且也有历史性的发生。
我认为PM2可能存在问题或存在问题,因为我也无法通过命令行在PM2上启动文档。
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.
答案 0 :(得分:0)
我放弃了这个主意。我不能仅从已记录的命令行在pm2中启动站点,以及github问题,这预示着一个很好的事实。
我决定只使用npm run build
并通过IIS提供静态文件。我们将需要编写服务器端脚本,以便用户可以更新内容,重新运行构建并更新IIS的静态文件。
答案 1 :(得分:0)
你的问题解决了吗?
我在macos下运行没有问题,pm2版本是5.1.0
请尝试:在终端上运行“npm start”
答案 2 :(得分:0)
这是更简洁的最新答案:
"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' 的 'script' 键和值为 'run' 的 'args' 键。在我们的例子中,脚本名称是“shivkumarscript”。
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
...还有嘘!伙计们