Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use child_process.fork when running node scripts... #1134

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/monitor/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ var debug = require('debug')('nodemon');
var utils = require('../utils');
var bus = utils.bus;
var childProcess = require('child_process');
var spawn = childProcess.spawn;
var exec = childProcess.exec;
var fork = childProcess.fork;
var spawn = childProcess.spawn;
var watch = require('./watch').watch;
var config = require('../config');
var child = null; // the actual child process we spawn
Expand Down Expand Up @@ -71,6 +72,7 @@ function run(options) {

var args = runCmd ? utils.stringify(executable, cmd.args) : ':';
var spawnArgs = [sh, [shFlag, args]];

debug('spawning', args);

if (utils.version.major === 0 && utils.version.minor < 8) {
Expand All @@ -82,7 +84,14 @@ function run(options) {
});
}

child = spawn.apply(null, spawnArgs);
if (executable === 'node') {
var forkArgs = cmd.args.slice(1);
child = fork(options.execOptions.script, forkArgs, {
env: utils.merge(options.execOptions.env, process.env),
});
} else {
child = spawn.apply(null, spawnArgs);
}

if (config.required) {
var emit = {
Expand Down