NodeJS - Node child process?

I am using NodeJS to start a socket server (using socket.io). When the client connects, I want to open and run a module that does a bunch of things. Despite the fact that I try to try and catch as much as possible when this module throws an error, it obviously removes the entire socket server from it.

Is there a way I can separate the two, so if the connected client script module fails, it will not necessarily result in the removal of the entire server?

I assume that this requires a child process, but the documentation does not mention starting other instances of node.

I would obviously have to kill the process if the client also disconnected.

+5
source share
2 answers

, , , JS-. , vm module. , try / catch .

node , spawn, stderr/stdout/ . kill , . , .

, uncaughtException "" , , 't (, , ).

+5

, "vm", , , .

, 'vm':

Note that running untrusted code is a tricky business requiring great care. 
To prevent accidental global variable leakage, vm.runInNewContext is quite 
useful, but safely running untrusted code requires a separate process.

, nodejs , , , .

- " () ... ", , , , , .

+1

All Articles