Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

allow options without args in fork #2424

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion doc/api/child_processes.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ subshell but rather the specified file directly. This makes it slightly
leaner than `child_process.exec`. It has the same options.


### child_process.fork(modulePath, arguments, options)
### child_process.fork(modulePath, [arguments], [options])

This is a special case of the `spawn()` functionality for spawning Node
processes. In addition to having all the methods in a normal ChildProcess
Expand Down
16 changes: 13 additions & 3 deletions lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,23 @@ function setupChannel(target, channel) {

function nop() { }

exports.fork = function(modulePath /*, args, options*/) {

exports.fork = function(modulePath, args, options) {
if (!options) options = {};
// Get options and args arguments.
var options, args;
if (Array.isArray(arguments[1])) {
args = arguments[1];
options = arguments[2] || {};
} else {
args = [];
options = arguments[1] || {};
}

args = args ? args.slice(0) : [];
// Copy args and add modulePath
args = args.slice(0);
args.unshift(modulePath);

// Don't allow stdinStream and customFds since a stdin channel will be used
if (options.stdinStream) {
throw new Error('stdinStream not allowed for fork()');
}
Expand Down