I am trying to run Docusaurus on Windows Server 2016 with Node.js version 12.14.0 via PM2 on IIS10. I am using PM2 so I can have the apps restart after a server reboot. I have to admit now that today is the first time I have ever attempted anything with Node.js, so please bear with me.
This is usually run by calling npm run start
within the Docusaurus directory. When testing out Node.js and whether a 'Hello World' app would start on reboot of the server, I was using the ecosystem.config.js
as suggested in the PM2 documentation. This called a javascript file like so.
module.exports = {
apps: [
{
name: "HelloWorld",
script: "apps\\hello_world.js",
instances: 1
}
]
}
This worked fine, but I could not find any documentation on how to run npm start
from this file though (although I did try calling a separate batch file, which also didn't work). Then I saw here that I could call a JSON file that documented further options.
JSON configuration file:
{
"apps": [
{
"name": "docs",
"cwd": "apps\\docs",
"script": "npm",
"args": "start"
},
{
"name": "HelloWorld",
"script": "apps\\hello_world.js"
}
]
}
The 'HelloWorld' script starts, but not the docs app.
pm2 report offers the following output:
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"
Which brought me to this issue on GitHub. There doesn't seem to be a lot of activity on the issues there though, and there were historic occurrences of it too.
I think there may be something I am doing wrong with PM2 or there is a problem with it, because I cannot launch docs via the command line with PM2 either.
C:\Node JS\apps\docs>pm2 start npm --name "docs" -- start
Has anyone got any ideas on how I can get this to work or has tried to do anything similar? I would settle for an answer on:
Apologies if I have rambled.
EDIT:
Output of 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'
The log it references is empty. The docs-error.log
repeats the same error repeatedly, but has not been updated since last night. It was probably created from me trying out different syntaxes in the JSON file, but posting it anyway.
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.
The problem was actually how pm2 calls node via a batch file on Windows. If you call npm-cli.js
directly with its full path the program will run without issue.
{
"apps": [
{
"name": "docs",
"cwd": "some_path_to\\apps\\docs",
"script": "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js",
"args": "start",
"exec_mode": "cluster",
"instances": 1,
"interpreter": "none"
}
]
}