pm2
pm2 copied to clipboard
How to get rid of annoying popups in Windows 10?
How do I disable the popup windows that pm2 generates in Windows 10 when starting, restarting or reloading a Node.js app? From the perspective of rapid server-side development, this is very annoying...
Would it be an issue because of the way we spawn processes?
- https://github.com/Unitech/pm2/blob/development/lib/God/ClusterMode.js#L52
- https://github.com/Unitech/pm2/blob/development/lib/God/ForkMode.js#L94
I don't know if I have to customize something on this code segments,
{detached: true should get rid of this error but it is not available for cluster.
interesting, maybe @ThisIsMac47 will have a look at this on the next weeks
After testing, the detached option doesnt hide popups on Windows, i think that nodejs spawn a shell to spawn the process. I will investigate more in the next days.
Okay so :
- In fork mode, you shouldnt have popups in the dev branch since now
- In cluster mode, unfortunately, we dont have control on the popup cause we use the cluster implementation of nodejs.
If you get any popup apart of cluster mode, respond to this issue to report it, i will investigate for each one.
Because we can't get detached: true in cluster?
They use the function fork, we can use detached: true only with spawn.
Yes ok so if that's the main reason, the only solution is to port cluster into pm2 instead of using the nodejs cluster. Did you try a simple cluster implementation without pm2 to see if it pops up too?
I wasnt able to reproduce with a simple cluster implementation, this might coming from the fact that we are a spawning a child from a forked child or something like this. We manage to delete the popups in cluster mod by rewriting the implementation on the branch of a forked cluster implementation, we will talk about how include this into future release of pm2.
Is this issue fixed or any workaround available? I have faced the same issue when using cluster mode with watch option. The node window opens multiple time when saving the file.
@ajithr No, like i said, the problem come from nodeJs implementation of the cluster mode. I suggest you to develop in fork mode.
For me what has been working quite well is to use --no-daemon.
However, if pm2 was previously started as a daemon process, then this flag has no effect and the popups keep appearing, unless I run pm2 kill.
@gustavohenke I followed your instructions, but it did not work for me. I am using pm2 2.0.19 on Windows 8.1 and I still get a popup window everytime I use child_process.exec()
@centigrade-thomas-becker The fact a popup is spawning when you call child_process.exec isn't coming from pm2, it come from the system of spawning a child process of node itself, you may add detached: true to the spawning config and it will not spawn any popup.
The problem of #2182 is that in cluster mode, we can't control how the process are spawn, so we can't add this options to hide the popup under windows.
@centigrade-thomas-becker you should try to use child_process.spawn and add a {detached: true} option.
I wanted to share what I did to overcome the popup.
Initially I will npm start my app that starts pm2 as well, then I will do pm2 stop all immediately. After that when I again do npm start, it just pops up only once and never again.
Do we have any updates on this for a proper implementation that will patch this issue?
I use PM2 when locally developing. It's becoming an issue to run pm2 kill after every script run. Consoles interrupting me when working is not welcome.
Try this,
npm startyour project as usual (pop-up's keep on coming up)- Stop the project (
Ctrl-C) pm2 delete <project-name>- Again
npm start(this time it stops popping up)
Hope it works!
I use the process json file to launch my pm2 instances so I do not believe that will work for me. On Fri, 31 Mar 2017 at 1:07 pm, Raghav Manikandan [email protected] wrote:
Try this,
- npm start your project as usual (pop-up's keep on coming up)
- Stop the project (Ctrl-C)
- pm2 delete
- Again npm start (this time it stops popping up)
Hope it works!
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Unitech/pm2/issues/2182#issuecomment-290694966, or mute the thread https://github.com/notifications/unsubscribe-auth/AQFo-gSTsM1ff6b76yV4Qj20hfUV-uF4ks5rrOyHgaJpZM4Ijsqx .
Any fix to this? Just asking 😄
I wanted to share what I did to overcome the popup. Initially I will npm start my app that starts pm2 as well, then I will do pm2 stop all immediately. After that when I again do npm start, it just pops up only once and never again.
@mswaminath Can you please post your pm2 config, and how you spawn your child processes?
Any permanent solution for this ??
This issue is especially terrible if you have autorestart enabled, and something causes your script to crash after it loads (I accidentally renamed a file the script frequently reads from). Then all hell breaks loose! Windows are spawning and crashing so fast, I couldn't type or click on anything since the windows spawn in the foreground with focus. It's completely ignoring "max_restarts" and "restart_delay" (i'm guessing these don't apply to clusters). I literally had no choice but to hard reset my computer.
Wow it feels like I just won a game of solitaire
So for production applications it is imperative to take the weight off the single event loop by forking a few processes to balance the load. Well, fork() does not take a detached option, and nor should it. Once the primary process fails the child processes will be closed subsequently, allowing pm2 to respawn the parent which will re-fork children, while keeping only 1 instance of each process and maintaining the IPC pipe between them. This is quite simple and the forking nature of the node parent process is beautiful in this regard in my opinion.
At this point our only option is to use pm2 to create 4 actual and separate node apps. This may work, maybe. I have no idea how we will accomplish any kind of IPC messages back and forth from the processes considering there is no parent process to route the messages.
In other words, pm2 for production purposes on windows is currently not working. I will mention that if anyone can find time to resolve this issue, we will be happy to finance your hourly work in the name of getting this problem solved ASAP.
Thank you.
I have found a very simple fix that am using now for development,
- On your pm2 config file, just remove/comment the
instances: 1line pm2 delete <project-name>(one time process)npm start
Then you will see the magic, but I suggest to use this only for development.
We aren't using a config file. Our master process forks into sub-processes. Will this work for that?
SOLVED.
Use winsw and run "node myapp.js" as a windows service.
https://github.com/kohsuke/winsw
Any updates on this? I run multiple instances so cannot write off instance support.
I've opened this ticket with nodejs: https://github.com/nodejs/node/issues/15217
Would be great if everyone watching this ticket went and upvoted and shared this one. Really it seems like something that wouldn't be high impact for them to fix!
I think this is occurring for me on exec processes called by PM2 process management. I am using fork mode. What do you think, does this occur for subprocesses started with exec even with fork?
Any updates?
child_process.spawn::windowsHide option is already awailable:
https://github.com/nodejs/node/issues/15217#ref-pullrequest-267864790
https://github.com/Unitech/pm2/pull/3255 https://github.com/nodejs/node/issues/15217#ref-pullrequest-267864790 thanks to @soyuka @milichev @cjihrig
May you try development branch @milichev ?
Is it possible to get this a little earlier than release?
Installed with no success. The same console fireworks on each watched file change -(
node -v
v8.9.0
yarn global add https://github.com/Unitech/pm2@development
Any update?
It was fixed for me
@FireController1847 Not for me I think.
git clone [email protected]:Unitech/pm2.git
cd pm2
git checkout development
npm link
cd \test
pm2 start test.js -i 2
Still got 2 black console windows poped up!
node --version v9.2.0 pm2 --version 2.8.0
I'm on Window 10.
Is there any wrong with my setup?
Ah, actually, you're right. The window does popup. Nevermind.
Unless i missed something, God.nodeApp(in lib/God/ClusterMode.js) called cluster.fork, which has no windowsHide parameter at all!? Dead end!
I got a hacky solution
diff --git a/lib/God.js b/lib/God.js
index bf3bedda..61178584 100644
--- a/lib/God.js
+++ b/lib/God.js
@@ -15,7 +15,7 @@
******************************/
var semver = require('semver');
-var cluster = require('cluster');
+var cluster = require('./cluster_hack');
var numCPUs = require('os').cpus() ? require('os').cpus().length : 1;
var path = require('path');
var EventEmitter2 = require('eventemitter2').EventEmitter2;
diff --git a/lib/God/ClusterMode.js b/lib/God/ClusterMode.js
index 3a1185a3..af9bf43a 100644
--- a/lib/God/ClusterMode.js
+++ b/lib/God/ClusterMode.js
@@ -10,7 +10,7 @@
* @author Alexandre Strzelewicz <[email protected]>
* @project PM2
*/
-var cluster = require('cluster');
+var cluster = require('../cluster_hack');
var cst = require('../../constants.js');
var Utility = require('../Utility.js');
var pkg = require('../../package.json');
@@ -49,7 +49,7 @@ module.exports = function ClusterMode(God) {
// { "args": ["foo", "bar"], "env": { "foo1": "bar1" }} will be parsed to
// { "args": "foo, bar", "env": "[object Object]"}
// So we passing a stringified JSON here.
- clu = cluster.fork({pm2_env: JSON.stringify(env_copy), windowsHide: true});
+ clu = cluster.fork({pm2_env: JSON.stringify(env_copy), pm2_windowsHide: true});
} catch(e) {
God.logAndGenerateError(e);
return cb(e);
diff --git a/lib/cluster_hack.js b/lib/cluster_hack.js
new file mode 100644
index 00000000..c1cfd86b
--- /dev/null
+++ b/lib/cluster_hack.js
@@ -0,0 +1,18 @@
+var child_process = require('child_process');
+var oldFork = child_process.fork;
+child_process.fork = function () {
+ var pos = 1;
+ if (pos < arguments.length && Array.isArray(arguments[pos]))
+ pos++;
+ if (pos < arguments.length && arguments[pos] != null
+ && typeof arguments[pos] === 'object'
+ && arguments[pos].env && arguments[pos].env.pm2_windowsHide) {
+ arguments[pos].windowsHide = true;
+ arguments[pos].silent = true;
+ }
+ return oldFork.apply(this, arguments);
+};
+var cluster = require('cluster');
+child_process.fork = oldFork;
+
+module.exports = cluster;
But still get black windows flashing when pm2 stop x pm2 kill pm2 update ...
edit: I make a fork, toddwong/pm2@dc184e9ef76badbb565d9d61f6d39d4dda712db5
This should be fixed in nodejs then no?
@soyuka Not sure, but I've filed a feature request nodejs/node#17370
But the black windows during pm2 stop x etc. should be address in pm2 I think.
When using fork with watch activated, a black window flashes everytime a change is detected.
Is this normal behavior?
It seems is almost done https://github.com/nodejs/node/pull/17412
Meanwhile, if this helps someone: [email protected] is the last version that doesn't show pop-ups for me on win7, fork mode (above that, it doesn't matter if I run fork mode or cluster, it always shows popups).
Should work now, please try latest pm2 published:
$ npm install pm2 -g
$ pm2 update
Unfortunately continues spawning these windows 😞

Node: v9.4.0 OS: Windows 10 pm2: v2.9.2
Command: pm2 start app.js -i max
terminal: tested in git-bash, cmd and powershell
The server script:
const http = require("http");
const server = http.createServer(handler);
const port = 4875;
server.listen(port, () => {
console.log("Listening at port %d", port);
});
function handler(req, res) {
res.end("Holita desde Node.js");
}
Issue persists on windows 10 (pm2 version 2.9.3, node 9.4)
The prompts are only vissible for half a second though. Less than the 4 seconds of previous versions.
PM2 3.0.0 has been released:
$ npm install pm2@latest -g
$ pm2 update
Be aware of breaking changes, especially drop support for node 0.12. Full list here : https://github.com/Unitech/pm2/blob/master/CHANGELOG.md
And why was this issue closed? After updating to pm2 3.0.0, I still have the same issue...
It was closed cause we merged a PR which try to fix this issue. We were waiting for feedback about it.
And why was this issue closed? After updating to pm2 3.0.0, I still have the same issue...
Mhh did you update pm2 in memory? the windowsHide feature added in nodejs should fix this.
I updated to 3.0 by running npm install pm2 -g and then pm2 update . Window is still popping up for me.
Should we be using a specific node version to fix this? I see that 8.8 added the windowsHide feature and I'm using 8.11.2.
Also tried on latest Node 10.6.0 and window still appears
Still experiencing windows popping up with 3.0.3.
After starting a bunch of node services via pm2 start <configFile>, once in a while a cmd window pops up. Before I can get an idea what it displays, it's closed again. It seems this happens in a quite regular interval (every ~30 seconds).
UPDATE: I made a screencast in order to see this window popping up before it's closed again. At least, I can tell you that it's the Windows Management Instrumentation Command (wmic.exe) regularly being executed. Unfortunately, there is no information in the shell window which command might be run.
Hey guys, After playing with this error for a little while, I fixed it by using the NODE.JS Child_Process Documentation.
https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback
In my app the first file to be read is the index.js on the root of the app.
In the Documentation the lines look like this: const { spawn } = require('child_process');
const subprocess = spawn(process.argv[0], ['child_program.js'], { detached: true, stdio: 'ignore' });
subprocess.unref();
But,
I added the follow lines in my index.js file:
const { spawn } = require('child_process');
const subprocess = spawn(process.argv[0], ['index.js'], { stdio: 'ignore', windowsHide: true });
subprocess.unref();
Notice I remove the detached and add the windowsHide. And it works like charm! Good luck! Cleber
It was closed cause we merged a PR which try to fix this issue. We were waiting for feedback about it.
Shouldn't we document that when using a child process, the developper should use the windowsHide option?
Shouldn't we document that when using a child process, the developper should use the windowsHide option?
Problem is : we will copy/paste nodejs documentation. This work is not really ours but it's developer's responsibility. Anyway we can add a little explanation.
But I'm not sure everyone who has this issue is because of child process.
Sorry guys, after a little while I notice that node was consuming so much memory after I did the adjustment I mention above. Well, I came into another solution: Here we go:
package.json { "scripts": { "build": "webpack --config prod.config.js && pm2 start server.js" }, "proxy": "//example.com:3000" } This will allow the static files to be served in the same port without conflict! But you can run it in a different port but there is more to be done!
server.js
const express = require('express') const app = express()
app.get('/', (req, res) => res.send('Hello World!'))
app.listen(3000, () => console.log('Example app listening on port 3000!'))
Well, I did notice any memory leak but I will keep my eyes open and I will double check later. I hope it leads to a good solution for you guys!
With 3.1.2 it got even worse. Every 10 or 20 seconds, for each started app a window is (really fast) opened and closed. With 10 started apps, it's not really that usable.
Are there any workarounds for this ? I've tried using @cleberar38 's implementation but it still spawns popups.
Same here with version 3.1.3. Cmd windows every 10 seconds. It leaves the computer unusable for any purpose other than serving.
Only node >= 9.4.0 supports windowsHide in cluster.settings. So this only works for node >= 9.4.0 with pm2 cluster mode. And you have to take care of you own child processes as well.
any solution ? cmd windows opened and closed.
@toddwong
Hey, I apologize for asking for your time but would you be willing to write up instructions here on how to change this.
I am able to set PM2 to cluster, but I do not see where to place " windowsHide " What does it mean to take care of your own child processes ?
Any answers are appreciated but there are enough users here that need a work around that it would help greatly to have this explained
Thank you !
PM2 3.0.0 has been released:
$ npm install pm2@latest -g $ pm2 updateBe aware of breaking changes, especially drop support for node 0.12. Full list here : https://github.com/Unitech/pm2/blob/master/CHANGELOG.md
Fixed my issue. in Windows 10
@inkhsutesou I mean if you call child_process.fork/exec/... in your own scripts, you'd have to set the windowsHide flag to true in the parameters.
if you call cluster.fork in your own scripts, and you are working with node >= 9.4.0, you'd have to set the windowsHide flag to true when you call cluster.setupMaster. if you are working with node < 9.4.0, there isn't that windowsHide flag at all, and the black window may unavoidable.
I am running standard, out of the box configuration on Windows 8 and Node 10.11. What do I need to do to make the console flashing stop?
PM2 version 3.1.3.
8.x is the current LTS branch. Was this fix merged into any specific 8.x release, or do we need to wait for 10.x LTS?
Latest version without this behavior for me is 3.0.3, every version to latest (3.2.2) - still occure.
I can confirm what @duchu-net indicated in his comment
- no popup in
PM2 v3.0.3 - Popups appear starting from
v3.1.0all the way tov3.2.2
Edited for clarity: Running in the following environment
Node v10.11.0Npm v6.4.1Yarn v1.9.4
@JoeTheFkingFrypan which version of Node?
@atuttle I am using the following
Node v10.11.0Npm v6.4.1Yarn v1.9.4
Fair enough. Doesn't help those of us that would prefer to stay on Node LTS 8.x until 10.x becomes LTS though.
Guys I dont know how but after reinstaling PM2 i dont see this problem anymore. I also had problem with popups when launching gekko bot with pm2.
I cant say what i did, - Im only start study Node.js and else. To understand more how npm work i was delete pm2, install it local and global couple times. I was also deleted some catalogs and files in my user directory and in catalogs in AppData directory.
Sorry for this useless post I just want to say that solution exist. And maybe some one with more experience will find the answer.
pm2 3.2.2 Windows 10 node v8.11.3 npm 5.6.0
After few hours I just installed pm2 for the first time on my second PC, I don’t see this problem at all.
Experienced this with a node and pm2 installation done today. Everything is the latest. Still too many annoying pop ups.
I am also experiencing this issue.
Node : v8.11.1 Pm2 : 3.2.2 OS : Windows 10 NPM : 5.6.0
I can confirm what @duchu-net indicated in his comment
- no popup in
PM2 v3.0.3- Popups appear starting from
v3.1.0all the way tov3.2.2Edited for clarity: Running in the following environment
Node v10.11.0Npm v6.4.1Yarn v1.9.4
it really works! thanks!
I was experiencing this issue, and I solved with a json configuration to run my apps (I suggest to use this only in development mode)
{
"apps": [
{
"name": "apigateway",
"script": "./../apigateway/ApiGateway.js",
"exec_mode": "fork",
"env": {
"NODE_ENV":"development"
}
},
{
"name": "mainSrv",
"script": "./../main-srv/ExpressServer.js",
"exec_mode": "fork",
"env": {
"NODE_ENV":"development"
}
}
]
}
Hope it helps!
I also get this issue. Thanks for peoples suggestions above to resolve it, but none of them worked for me. I used an ecosystem.config.js and saw identical behaviour to running the app without it.
Node: 10.10.0 PM2: 3.03, 3.2.2 (note: running in fork mode) O/S: Windows 10 NPM: 6.4.1
@toddwong @cleberar38 The windowsHide flag that was mentioned - how would I use that in my setup please? I am using pm2 to run a script from package.json currently. Can I still somehow edit the index.js to add that flag?
package.json
...
"scripts": {
"build": "rimraf dist && babel src -d dist",
"test:e2e": "dotenv -e envs/test.env -e envs/.env ./scripts/e2e.test.sh",
"serve": "yarn run build && node dist/index.js"
}
...
e2e.test.sh
#!/usr/bin/env bash
...
if ! netstat -aon | grep "0.0.0.0:$SERVER_PORT" | grep "LISTENING"; then
pm2 -s start ./scripts/serve.js
until netstat -aon | grep "0.0.0.0:$SERVER_PORT" | grep "LISTENING"; do
sleep $RETRY_INTERVAL
done
...
pm2 delete all
serve.js (had to use this as a workaround for another issue I had using pm2 in my environment)
var cmd = require('node-cmd');
cmd.run('npm run serve');
If anyone has other suggestions or thinks they can fix, I will happily test them out :)
@msm1089 try this:
var exec = require('child_process').exec;
exec('npm run serve', {windowsHide: true});
@toddwong Perfecto! I briefly see a couple of cmd windows open, but they go away and stay away :)
thanks for figuring out this, I'm using node app with pm2 on windows server 2016 and both exec and spawn call are now not flashing any cmd popups. ( they are staying hidden )
pm2 version : 3.2.2 node 10.14.1
As @TheOptimisticFactory suggested, downgrading pm2 to 3.0.3 does the job for Node 8.x users.
Thank you !
reverting to PM2 3.0.3 indeed fixes this problem. Still worth a bump I think.
Just tried the current version 3.3.1 and there it's getting worse. Pm2 doesn't stop to open and instantly close pop ups. It was quite difficult to enter "pm2 stop all".
Still annoyed by this issue..
Last version where this not appears is "pm2": "3.0.3". That means, it was fixed and after 3.0.3 it is back again.
So I can't upgrade to 3.4.0. It is not possible to develop when the window pops up and closes on any change.
same issue. v3.4.0 popup 4 window every second and disappear quickly too
v3.0.3 does not work for me. But v2.10.4 (with node 6.4 ) does not pop at all.
If anyone have a clue of which option should be passed to spawn function to avoid this behavior that is welcome.
Here is the culprit: https://github.com/Unitech/pm2/blob/master/lib/God/ForkMode.js#L98
child_process - windowsHide not working with detached: true It seems a bug of node. Maybe you should change a way to start Daemon @Unitech. I use a detached process to start Daemon.js.Then run pm2 start, it do well.
If you use npx pm2 kill and npx pm2 start --no-daemon to start the dev server,
editing node_modules/pm2/lib/God/ForkMode.js:93 and changing detached : false, to detached : true, it doesn't create annoying popups.
System: node -v v11.14.0 npm -v 6.7.0 pm2: "^3.5.0", windows 10
Same issue. I've tried different node versions and different pm2 versions, it still doesn't work.
Node: 8.2.1, 10.12.0, 10.14.1, 10.16.0 PM2: 3.0.3, 3.5.1 Windows 10
If I run some simple code like this blow, it won't popup windows.
pm2 start test.js
setInterval(() => {
console.log('test...');
}, 50);
In the opposite way that running a big system would cause so many popups and super fast. Only I can do is rebooting.
As a workaround you can use pm2 on a linux subsystem. It works pretty well.
Any updates? I want develope node apps on windows