0

Im forking my nodejs process into 4 child-processes. One of this child-processes is for testing purposes The others are production.

Is there a way to restart the child-process with taking the changed files into account without having to restart the whole nodeprocess?

InsOp
  • 2,425
  • 3
  • 27
  • 42
  • You cannot just kill your spawned process and then restart it? It should use the latest files then.. – Anton Harald Apr 02 '16 at 09:38
  • @AntonHarald is that so? tbh i didnt tried yet, because it seemed illogical to me – InsOp Apr 02 '16 at 09:41
  • 1
    I didn't try it. But I'm quite sure - if I understand your problem correctly. Forking seems to be like spawning, just better suited for nodejs processes in particular. So if I do var cp = require("child_process"); var a = cp.spawn("myapp"); a.on('data'.... ; a.kill(); then, change the code of myapp and do the same thing for var b, I should get the latest version of myapp running. – Anton Harald Apr 02 '16 at 10:06

1 Answers1

1

See a detailed description how to communicate with forked node-js processes from within a node process here.

The question was, if code-changes in a forked process are taken in account, when the fork is restarted. Yes they are.

once you start a new fork via

var sub = require("child_process").fork("my_module.js");

the current code is read from the actual file. You can stop the fork via sub.disconnect() and reload it again.

Community
  • 1
  • 1
Anton Harald
  • 5,772
  • 4
  • 27
  • 61