Pm2: PM2 is unable to run server.js on Windows 10

Created on 3 Apr 2017  Β·  47Comments  Β·  Source: Unitech/pm2

I'm opening this issue because:

  • [x] pm2 isn't behaving like it should do.

What's going wrong?

I am unable to start node application using PM2
I have node version 7.5.0
npm version 4.4.4
PM2 version 2.4.3
Windows 10

I am trying to start the app using

pm2 start npm -- start

Package.json

{
  "name": "eems-api",
  "version": "1.0.0",
  "description": "Enterprise Expense Management API",
  "main": "server.js",
  "scripts": {
    "start": "npm run apidoc && babel-node server.js",
    "clusters": "babel-node clusters.js",
    "apidoc": "apidoc -i routes/ -o public/apidoc",
    "test": "SET NODE_ENV=test mocha test/**/*.js"
  },
  "apidoc": {
    "name": "EEMS API - Documentation",
    "template": {
      "forceLanguage": "en"
    }
  },
  "author": "Nitin Mukesh",
  "license": "restricted",
  "dependencies": {
    "babel-cli": "^6.5.1",
    "babel-preset-es2015": "^6.5.0",
    "bcrypt": "^0.8.7",
    "body-parser": "^1.15.0",
    "compression": "^1.6.1",
    "consign": "^0.1.2",
    "cors": "^2.7.1",
    "express": "^4.15.2",
    "helmet": "^1.1.0",
    "jwt-simple": "^0.4.1",
    "memwatch-next": "^0.3.0",
    "morgan": "^1.6.1",
    "passport": "^0.3.2",
    "passport-jwt": "^2.0.0",
    "sequelize": "^3.19.2",
    "sqlite3": "^3.1.8",
    "winston": "^2.1.1"
  },
  "env": {
    "PYTHON": "D:/Python27"
  },
  "devDependencies": {
    "apidoc": "^0.15.1",
    "babel-register": "^6.5.2",
    "chai": "^3.5.0",
    "mocha": "^2.4.5",
    "supertest": "^1.2.0"
  }
}

error log

D:\NODEJS\NPM.CMD:1
(function (exports, require, module, __filename, __dirname) { :: Created by npm, please don't edit manually.
                                                              ^
SyntaxError: Unexpected token :
    at Object.exports.runInThisContext (vm.js:73:16)
    at Module._compile (module.js:543:28)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Object.<anonymous> (C:\Users\nitin.mukesh\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainerFork.js:53:21)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)

it works fine using npm start

server.js

import express from "express";
import consign from "consign";

const app = express();

consign({verbose:false})
    .include('libs/config.js')
        .then('db.js')
            .then('auth.js')
                .then('libs/middlewares.js')
                    .then('routes')
                        .then('libs/boot.js')
                            .into(app);

module.exports = app;

Most helpful comment

pm2 for windows sucks!

All 47 comments

D:\XAMPP\htdocs\nodewebservice\eems>pm2 start npm -- start
[PM2] Applying action restartProcessId on app npm
[PM2] [npm](0) βœ“
[PM2] Process successfully started
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ App name β”‚ id β”‚ mode β”‚ pid β”‚ status β”‚ restart β”‚ uptime β”‚ cpu β”‚ mem β”‚ watching β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ npm β”‚ 0 β”‚ fork β”‚ 10432 β”‚ online β”‚ 45 β”‚ 0s β”‚ 23% β”‚ 8.1 MB β”‚ disabled β”‚
β”‚ server β”‚ 1 β”‚ fork β”‚ 0 β”‚ errored β”‚ 15 β”‚ 0 β”‚ 0% β”‚ 0 B β”‚ disabled β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Use pm2 show <id|name> to get more details about an app

Could you please provide your windows/pm2/nodejs version ?

I provided that in my first post

I have node version 7.5.0
npm version 4.4.4
PM2 version 2.4.3
Windows 10

@nitinmukesh My bad sorry
Do you by any chance use the Bash on Windows feature to use PM2 ? Could you tell me which shell you are using ?

Sorry I did not used the template to add post, my bad.

I am using Command prompt. I search for cmd and right click > run as administrator.
Not using anything else. Sorry if I missed any steps but not sure.

but my server works fine with the following command
npm start
OR
npm run clusters

is there any conflict with the package(s) included in package.json

Do you use babel at runtime ? If yes, please read http://pm2.keymetrics.io/docs/tutorials/using-transpilers-with-pm2
Otherwise i don't see other possibility so i'll need a simple file to reproduce the issue myself and if needed fix the problem inside pm2.

Thank you vmarchaud.
I am using ES6 and using babel. If I understand I need to create production build and then use pm2.

If you want to keep the cluster mode you need to use require('babel-register'); in another file (read the doc), if you don't care just run :

  • npm install -g babel-cli

    • pm2 start --interpreter babel-node server.js

I have same issue on Win10.

"scripts": {
    "start": "better-npm-run start-dev",
},
"betterScripts": {
    "start-dev": {
      "command": "webpack-dashboard -- node ./implements/server.dev.njs",
      "env": {
        "NODE_ENV": "development",
        "PORT": 3000
      }
    },
module.exports = {
  apps: [
    // Static application server
    {
      name: 'server',
      script: 'npm',
      args: 'start',
    }
  ],
};

And when i try pm2 start ecosystem.config.js

0|server   |     at Object.Module._extensions..js (module.js:579:10)
0|server   | C:\PROGRAM FILES\NODEJS\NPM.CMD:1
0|server   | (function (exports, require, module, __filename, __dirname) { :: Created by npm, please don't edit manually.
0|server   |                                                               ^
0|server   | SyntaxError: Unexpected token :
0|server   |     at createScript (vm.js:56:10)
0|server   |     at Object.runInThisContext (vm.js:97:10)
0|server   |     at Module._compile (module.js:542:28)
0|server   |     at Object.Module._extensions..js (module.js:579:10)
0|server   |     at Module.load (module.js:487:32)
0|server   |     at tryModuleLoad (module.js:446:12)
0|server   |     at Function.Module._load (module.js:438:3)
0|server   |     at Object.<anonymous> (C:\Users\Vera\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainerFork.js:53:21)
0|server   |     at Module._compile (module.js:570:32)
0|server   |     at Object.Module._extensions..js (module.js:579:10)

How i can start npm-scripts? it is possible?

same issue here also

C:\PROGRAM FILES\NODEJS\NPM.CMD:1
(function (exports, require, module, __filename, __dirname) { :: Created by npm, please don't edit manually.
                                                              ^
SyntaxError: Unexpected token :
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Object.<anonymous> (C:\Users\admin\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainerFork.js:53:21)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
C:\PROGRAM FILES\NODEJS\NPM.CMD:1
(function (exports, require, module, __filename, __dirname) { :: Created by npm, please don't edit manually.
                                                              ^
SyntaxError: Unexpected token :
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Object.<anonymous> (C:\Users\admin\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainerFork.js:53:21)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
C:\PROGRAM FILES\NODEJS\NPM.CMD:1
(function (exports, require, module, __filename, __dirname) { :: Created by npm, please don't edit manually.
                                                              ^
SyntaxError: Unexpected token :
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Object.<anonymous> (C:\Users\admin\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainerFork.js:53:21)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
C:\PROGRAM FILES\NODEJS\NPM.CMD:1
(function (exports, require, module, __filename, __dirname) { :: Created by npm, please don't edit manually.
                                                              ^
SyntaxError: Unexpected token :
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Object.<anonymous> (C:\Users\admin\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainerFork.js:53:21)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
C:\PROGRAM FILES\NODEJS\NPM.CMD:1
(function (exports, require, module, __filename, __dirname) { :: Created by npm, please don't edit manually.
                                                              ^
SyntaxError: Unexpected token :
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Object.<anonymous> (C:\Users\admin\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainerFork.js:53:21)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
C:\PROGRAM FILES\NODEJS\NPM.CMD:1
(function (exports, require, module, __filename, __dirname) { :: Created by npm, please don't edit manually.
                                                              ^
SyntaxError: Unexpected token :
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Object.<anonymous> (C:\Users\admin\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainerFork.js:53:21)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
C:\PROGRAM FILES\NODEJS\NPM.CMD:1
(function (exports, require, module, __filename, __dirname) { :: Created by npm, please don't edit manually.
                                                              ^
SyntaxError: Unexpected token :
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Object.<anonymous> (C:\Users\admin\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainerFork.js:53:21)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
C:\PROGRAM FILES\NODEJS\NPM.CMD:1
(function (exports, require, module, __filename, __dirname) { :: Created by npm, please don't edit manually.
                                                              ^
SyntaxError: Unexpected token :
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Object.<anonymous> (C:\Users\admin\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainerFork.js:53:21)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
C:\PROGRAM FILES\NODEJS\NPM.CMD:1
(function (exports, require, module, __filename, __dirname) { :: Created by npm, please don't edit manually.

This is closed, but no explanation how to solve this problem. Anyone?

pm2 for windows sucks!

+1

+1, this is still broken, it seems to stem from the fact that it's reading node.cmd in C:\Program Files\nodejs and trying to throw that in some function. Does anyone have any idea what it's supposed to be reading on Windows instead?

I am too having the same issue. Any solutions Guys !!

Same issue here :confused:

Still running into this issue. Anyone was able to solve?

Have the same issue

Same issue here on Windows 10. I'm using LTS(8.9.4) version of node.

I was struggling with this for a few days. The issue is that on windows, PM2 will try to interpret npm.cmd (presumably in JS), rather than literally execute it. If I had to guess, this isn't a problem on unix because pm2 knows to use bash (it doesn't have a cmd default interpreter), so it only looks like it's executing a command line function, or something along those lines - I haven't actually looked at the specifics of how NPM installs on unix. That's also why specifying an interpreter can sometimes fix the issue as @vmarchaud suggested.

Luckily the workaround is easy, and probably a better practice anyway.
Our solution was to point the "script" option at a new js script that uses node-cmd to run "npm start". EG:
var cmd=require('node-cmd'); cmd.run('npm start');

@theaceofthespade still won't help.

I am trying to run $lerna run start process via npm start (I want to have it handled & listed via pm2)
$npm run start what is running lerna run start works fine for me

same as @tresdev Windows 10. I'm using LTS(8.9.4) version of node.
It works fine on OSX High Sierra with nvm

>pm2 logs
[TAILING] Tailing last 15 lines for [all] processes (change the value with --lines option)
C:\Users\mysecretuser\.pm2\pm2.log last 15 lines:
PM2        | 2018-02-21 08:54:50: App [npm] with id [0] and pid [16492], exited with code [1] via signal [SIGINT]
PM2        | 2018-02-21 08:54:50: Starting execution sequence in -fork mode- for app name:npm id:0
PM2        | 2018-02-21 08:54:50: App name:npm id:0 online
PM2        | 2018-02-21 08:54:50: App [npm] with id [0] and pid [12796], exited with code [1] via signal [SIGINT]
PM2        | 2018-02-21 08:54:50: Starting execution sequence in -fork mode- for app name:npm id:0
PM2        | 2018-02-21 08:54:50: App name:npm id:0 online
PM2        | 2018-02-21 08:54:50: App [npm] with id [0] and pid [10512], exited with code [1] via signal [SIGINT]
PM2        | 2018-02-21 08:54:50: Starting execution sequence in -fork mode- for app name:npm id:0
PM2        | 2018-02-21 08:54:50: App name:npm id:0 online
PM2        | 2018-02-21 08:54:51: App [npm] with id [0] and pid [17792], exited with code [1] via signal [SIGINT]
PM2        | 2018-02-21 08:54:51: Starting execution sequence in -fork mode- for app name:npm id:0
PM2        | 2018-02-21 08:54:51: App name:npm id:0 online
PM2        | 2018-02-21 08:54:51: App [npm] with id [0] and pid [17568], exited with code [1] via signal [SIGINT]
PM2        | 2018-02-21 08:54:51: Starting execution sequence in -fork mode- for app name:npm id:0
PM2        | 2018-02-21 08:54:51: App name:npm id:0 online

C:\Users\mysecretuser\.pm2\logs\npm-out-0.log last 15 lines:
C:\Users\mysecretuser\.pm2\logs\npm-error-0.log last 15 lines:
0|npm      | C:\Users\myseceretuser\AppData\Roaming\nvm\v8.9.3\NPM.CMD:1
0|npm      | (function (exports, require, module, __filename, __dirname) { :: Created by npm, please don't edit manually.
0|npm      |
  • Windows 10
  • $ node -v v8.9.3
  • $ nvm -v Running version 1.1.6.
  • $ npm -v 5.5.1
  • $ pm2 -v 2.9.1

+1

@szymon-waite can you post your pm2 config?

@theaceofthespade basically it is default one. I am afraid, that windows nvm does not help.

pm2 ecosystem
[PM2] Spawning PM2 daemon with pm2_home=C:\Users\mysecretuser\.pm2
[PM2] PM2 Successfully daemonized
File ProjectPath\ecosystem.config.js generated

PS > pm2 ecosystem
File Project\ecosystem.config.js generated
PS Project> cat .\ecosystem.config.js
module.exports = {
  /**
   * Application configuration section
   * http://pm2.keymetrics.io/docs/usage/application-declaration/
   */
  apps : [

    // First application
    {
      name      : 'API',
      script    : 'app.js',
      env: {
        COMMON_VARIABLE: 'true'
      },
      env_production : {
        NODE_ENV: 'production'
      }
    },

    // Second application
    {
      name      : 'WEB',
      script    : 'web.js'
    }
  ],

  /**
   * Deployment section
   * http://pm2.keymetrics.io/docs/usage/deployment/
   */
  deploy : {
    production : {
      user : 'node',
      host : '212.83.163.1',
      ref  : 'origin/master',
      repo : '[email protected]:repo.git',
      path : '/var/www/production',
      'post-deploy' : 'npm install && pm2 reload ecosystem.config.js --env production'
    },
    dev : {
      user : 'node',
      host : '212.83.163.1',
      ref  : 'origin/master',
      repo : '[email protected]:repo.git',
      path : '/var/www/development',
      'post-deploy' : 'npm install && pm2 reload ecosystem.config.js --env dev',
      env  : {
        NODE_ENV: 'dev'
      }
    }
  }
};

User .pm2 folder structure: 

.pm2


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       18.02.2018     15:44                logs
d-----       29.12.2017     22:21                modules
d-----       21.02.2018     08:54                pids
-a----       15.02.2018     12:22              2 dump.pm2
-a----       13.02.2018     15:08          21794 dump.pm2.bak
-a----       29.12.2017     22:21              2 module_conf.json
-a----       21.02.2018     08:55         600128 pm2.log
-a----       21.02.2018     15:06              5 pm2.pid
-a----       29.12.2017     22:21             13 touch

And what's your app.js look like?

@theaceofthespade basically I am trying to run $npm start command what is running $lerna run start

So in package.json "scripts" section I've got : "start": "lerna run start".

My goal is to handle lerna process (what is running few more processes) with pm2 tool
At least it works fine on OSX, in Windows I've got above errors.

I've tried also node-cmd - without success

There's something missing somewhere in here. Where/how are you telling pm2 to run "nom start"

f.e. in Power Shell / cmd.exe . I am running from console:

$ pm2 start npm -- start / $ pm2 start npm -- start --

There's your problem - when you do that, you're telling pm2 to interpret the "npm script" with an argument of start. Try putting a npm-cmd call into a start script called startscript.js, and then doing pm2 start startscript.js.

Eg
npm install node-cmd --save;

in startscript.js:
var cmd=require('node-cmd'); cmd.run('npm start');

pm2 start startscript.js

sorry, I wrote "node start" in both my comments, but meant "npm start"

yeah that was the other half of the mistake - the package is node-cmd

There is :

nvm\v8.9.3\node_modules\pm2\lib\ProcessContainerFork.js:78:21)
0|windows- |     at Module._compile (module.js:635:30)
0|windows- |     at Object.Module._extensions..js (module.js:646:10)
0|windows- |     at Module.load (module.js:554:32)
0|windows- | TypeError: cmd.exec is not a function
0|windows- |     at Object.<anonymous> (Project\windows-pm2-starter.js:2:5)
0|windows- |     at Module._compile (module.js:635:30)
0|windows- |     at Object.Module._extensions..js (module.js:646:10)
0|windows- |     at Module.load (module.js:554:32)
0|windows- |     at tryModuleLoad (module.js:497:12)
0|windows- |     at Function.Module._load (module.js:489:3)
0|windows- |     at Object.<anonymous> (C:\Users\mysecretuser\AppData\Roaming\nvm\v8.9.3\node_modules\pm2\lib\ProcessContainerFork.js:78:21)
0|windows- |     at Module._compile (module.js:635:30)
0|windows- |     at Object.Module._extensions..js (module.js:646:10)
0|windows- |     at Module.load (module.js:554:32)

in pm2 logs but ...

It Works πŸ‘ πŸ₯‡ windows is running 2 black, blank cmd.exe with npm title, after closing it it is re-spawning process with logs:

M2        | App [windows-pm2-starter] with id [0] and pid [15920], exited with code [0] via signal [SIGINT]
PM2        | Starting execution sequence in -fork mode- for app name:windows-pm2-starter id:0
PM2        | App name:windows-pm2-starter id:0 online

but the goal has been achieved, I hope it is stable solution, thanks @theaceofthespade

Excellent! There may definitely be better implementations of this solution than using node-cmd (that was literally the first one I found so if you find something that seems to work better please let me know!), but the main point is that this bug is because one can't actually run command line commands from pm2 in windows.

Amazing!
Eg
npm install node-cmd --save;

in startscript.js:
var cmd=require('node-cmd'); cmd.run('npm start');

pm2 start startscript.js

Thanks!@theaceofthespad
image

@theaceofthespade: Thanks for the work around but that npm titled blank window is re spawning. How to get rid of this and just leave pm2 process quietly in the background.

@ihteshamqazi you can try the solution from #2182

var exec = require('child_process').exec;
exec('npm run serve', {windowsHide: true});

Thanks!@theaceofthespad
you save my day too

My solution:

{
  name: 'Frontend',
  cwd: `${__dirname}/frontend`,
  script: 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
  args: 'run dev',
}

Maybe will be helpful for someone.

@ihteshamqazi

For the backround pop up being infinetly spawn reverting to 3.0.3 helped
See here

https://github.com/Unitech/pm2/issues/2182#issuecomment-427773250

hu-qi's work around is effective but what if I want to the output to be captured in pm2 logs?

Amazing!
Eg
npm install node-cmd --save;

in startscript.js:
var cmd=require('node-cmd'); cmd.run('npm start');

pm2 start startscript.js

Thanks!@theaceofthespad
image

It's run the commands but not showing logs of api calling.

@ihteshamqazi you can try the solution from #2182

var exec = require('child_process').exec;
exec('npm run serve', {windowsHide: true});

it run the commands but not showing logs of api calling

Hello,
If you want to have stdout/stderr, use spawn instead exec, with the stdio option.
I use this startup script to start my node app on Windows:

const { spawn } = require('child_process')
console.log('***** starting server *****')
const srvproc = spawn('node', ['-r', './prod-paths.js', './dist/index.js'], { 
  stdio: 'inherit',
  windowsHide: true,
  env: {
    'NODE_ENV': 'production'
  }
})

Hope this helps.

So there is no fix, just workarounds?

I find another way to fix similar problem.
I have installed Git2.27.0 in Windows2008R2,
at Adjusting your PATH environment, choose
Use Git and optional Unix tools from the Command Prompt
make a shell format script myproject.sh such as:
java -jar -Dspring.config.location=application.yml myproject0.1.jar
and it works

pm2 start myproject.sh

This comment does solve it https://github.com/Unitech/pm2/issues/2808#issuecomment-291223512

You need to use the interpreter flag.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rangercyh picture rangercyh  Β·  4Comments

cchan picture cchan  Β·  3Comments

phra picture phra  Β·  3Comments

ghost picture ghost  Β·  3Comments

lefam picture lefam  Β·  3Comments