Execute the function in a new node process
1 answer
You can unblock new processes using child_process.fork . It accepts a separate module, but if you must contain it in one file, you can specify your script parameter:
var child_process = require('child_process');
var mode = process.argv[2] ? process.argv[2] : 'default';
var modes = {
default: function() {
console.log('I am the default, I will fork a child');
child_process.fork(__filename, ['child']);
},
child: function() {
console.log('I am the child!');
}
};
modes[mode]();
+4
source to share