0

I am trying to find a way of running my Nodejs app in the background. I did a lot of research and I am aware of them (node-windows, forever, nssm, ...).

During this what came to my mind was to create my OWN service wrapper in c++ which executes the script (windows) as a child process.

Therefore my question: Is it possible? and what are the possibilities to communicate with the node.exe executing my script? In Google in find tons of articles about the node "childprocess" module but nothing where the node.exe is the childprocess.

BTW: In one of the answers here on SO I found a solution with the sc.exe, but when I am installing the node.exe with the script it gets terminated because it does not respond to the SCM commands. Did this ever work?

Thank you alot in advance

Woife
  • 27
  • 8
  • Does the question apply to C++ wrapper only? It's unclear why you would make it that complicated. *In Google in find tons of articles about the node "childprocess" module but nothing where the node.exe is the childprocess.* - because it's not specific to node.exe, you just kill it as any other child process, likely with `kill()`. It's seamless for spawned processes in Node, https://stackoverflow.com/questions/20187184/how-to-kill-childprocess-in-nodejs – Estus Flask Jun 07 '18 at 10:55
  • Yes I already thought in this direction but is already learned that windows does not support such signals. This is the reason why I asked for communication possibilities. (Mainly for terminating the node process in a good way). Would be nice if someone would have the answer to this immediately so I can save the time for testing this stuff. Edit: yes c++ wrapper only – Woife Jun 07 '18 at 14:24
  • If your problem is to kill a process gracefully, I'd suggest to re-ask a question directly, because this isn't really related to NodeJS, only to C++ part, and it's not about executing, it's about killing. *In one of the answers here on SO I found a solution with the sc.exe, but when I am installing the node.exe with the script it gets terminated because it does not respond to the SCM commands. Did this ever work?* - it's unclear what it's all about. If you have code-related problem, the question should contain https://stackoverflow.com/help/mcve . – Estus Flask Jun 07 '18 at 15:33
  • No the problem is not killing the process... I am pretty sure the windows c++ function can do that but it strongly depends on the implementation of the node.exe. (Do my script in the end get noticed the right way if I do this? e.g. the exit event of the process variable inside of the script). I can no post such a question because it would be closed because it is to general. – Woife Jun 07 '18 at 21:44
  • I would suggest to provide your example implementation of C++ part in order for this question to not be considered too general, because it is in its current state. – Estus Flask Jun 07 '18 at 22:06

1 Answers1

0

You can make the process run in background using pm2

pm2 start app.js --watch This will start the process and will also look for changes in the file. More about watch flag

Rubin bhandari
  • 1,873
  • 15
  • 20
  • Yes I also saw this one, but for now I am more interested in the communication possibilities. Especially how to terminate the Nodejs Subprocess gracefully. – Woife Jun 07 '18 at 09:01
  • Btw: can you tell my how PM2 achieves to run in the background? I dont see a windows service which was installed. Is this possible for custom scripts aswell? – Woife Jun 13 '18 at 07:34