Reputation: 3246
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.
Upvotes: 2
Views: 8985
Reputation: 3246
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"
}
]
}
Upvotes: 5
Reputation: 3285
This is bit cleaner and latest answer:
"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"
}
Suppose we want to run the script named as 'shivkumarscript' with pm2 utility. So, our pm2 config file should be like below, containing 'script' key with value as 'npm' and 'args' key with value as 'run '. Script name is 'shivkumarscript' in our case.
module.exports = {
apps: [
{
name: "NodeServer",
script: "npm",
automation: false,
args: "run shivkumarscript",
env: {
NODE_ENV: "development"
},
env_production: {
NODE_ENV: "production"
}
}
]
}
Assuming that you have already installed Node.js, NPM and PM2 on your machine. Then below should be the command to start the application through pm2 which will in turn run the npm script (command line mentioned in your application's package.json file):
For production environment:
pm2 start ecosystem.config.js --env production --only NodeServer
For development environment:
pm2 start ecosystem.config.js --only NodeServer
...And Boooom! guys
Upvotes: 0
Reputation: 1
have you solve your issue?
I run this under macos without problem, pm2 version is 5.1.0
please try: run "npm start" on your terminal
Upvotes: 0