Example: sending a server object
The argument can be used, for instance, to pass the handle of a TCP server object to the child process as illustrated in the example below:
Open up the server object and send the handle.
The child would then receive the server object as:
Once the server is now shared between the parent and child, some connections can be handled by the parent and some by the child.
While the example above uses a server created using the module, module servers use exactly the same workflow with the exceptions of listening on a event instead of and using instead of
This is, however, currently only supported on UNIX platforms.
Example: sending a socket object
Similarly, the argument can be used to pass the handle of a socket to the child process.
The example below spawns two children that each handle connections with "normal" or "special" priority:
Open up the server and send sockets to child.
Use to prevent the sockets from being read before they are sent to the child process.
If this is special priority
This is normal priority
The would receive the socket handle as the second argument passed to the event callback function:
Check that the client socket exists.
It is possible for the socket to be closed between the time it is sent and the time it is received in the child process.
Once a socket has been passed to a child, the parent is no longer capable of tracking when the socket is destroyed.
To indicate this, the property becomes
It is recommended not to use when this occurs.
It is also recommended that any handlers in the child process verify that exists, as the connection may have been closed during the time it takes to send the connection to the child.
A that represents the child process's
If the child was spawned with set to anything other than then this will be
is an alias for
Both properties will refer to the same value.
Note that if a child process waits to read all of its input, the child will not continue until this stream has been closed via
A sparse array of pipes to the child process, corresponding with positions in the option passed to that have been set to the value
Note that and are also available as and respectively.
In the following example, only the child's fd is configured as a pipe, so only the parent's is a stream, all other values in the array are
Use parent's for child
Pipe child's to parent
Direct child's to a file
The option specifies the largest number of bytes allowed on or
If this value is exceeded, then the child process is terminated.
This impacts output that includes multibyte character encodings such as UTF-8 or UTF-16.
For instance, will send 13 UTF-8 encoded bytes to although there are only 4 characters.
The shell should understand the switch on UNIX or on Windows.
On Windows, command line parsing should be compatible with
Default Windows Shell
Although Microsoft specifies must contain the path to in the root environment, child processes are not always subject to the same requirement.
Thus, in functions where a shell can be spawned, is used as a fallback if is unavailable.
Node.js comes with a variety of CLI options.
These options expose built-in debugging, multiple ways to execute scripts, and other helpful runtime options.
To view this documentation as a manual page in a terminal, run
Execute without arguments to start the
For more info about, please see the debugger documentation.
Alias for, analogous to the use of - in other command line utilities, meaning that the script will be read from, and the rest of the options are passed to that script.
Indicate the end of node options. Pass the rest of the arguments to the script. If no script filename or eval/print script is supplied prior to this, then the next argument will be used as a script filename.
Aborting instead of exiting causes a core file to be generated for post-mortem analysis using a debugger (such as and)
If this flag is passed, the behavior can still be set to not abort through (and through usage of the module that uses it).
Enable FIPS-compliant crypto at startup. (Requires Node.js to be built with
Enable experimental ES module support and caching modules.
Enable experimental top-level keyword support in REPL.
Enable experimental ES Module support in the module.
Force FIPS-compliant crypto on startup. (Cannot be disabled from script code.) (Same requirements as)
Specify ICU data load path. (Overrides)
Activate inspector on and break at start of user script.
Set the to be used when the inspector is activated.
Useful when activating the inspector by sending the signal.
V8 inspector integration allows tools such as Chrome DevTools and IDEs to debug and profile Node.js instances. The tools attach to Node.js instances via a tcp port and communicate using the Chrome DevTools Protocol.
This option is a no-op. It is kept for compatibility.
Silence deprecation warnings.
Disables runtime checks for
These will still be enabled dynamically when is enabled.
Silence all process warnings (including deprecations).
Load an OpenSSL configuration file on startup. Among other uses, this can be used to enable FIPS-compliant crypto if Node.js is built with
Emit pending deprecation warnings.
Pending deprecations are generally identical to a runtime deprecation with the notable exception that they are turned off by default and will not be emitted unless either the command line flag, or the environment variable, is set. Pending deprecations are used to provide a kind of selective "early warning" mechanism that developers may leverage to detect deprecated API usage.
Instructs the module loader to preserve symbolic links when resolving and caching modules.
By default, when Node.js loads a module from a path that is symbolically linked to a different on-disk location, Node.js will dereference the link and use the actual on-disk "real path" of the module as both an identifier and as a root path to locate other dependency modules. In most cases, this default behavior is acceptable. However, when using symbolically linked peer dependencies, as illustrated in the example below, the default behavior causes an exception to be thrown if attempts to require as a peer dependency:
The command line flag instructs Node.js to use the symlink path for modules as opposed to the real path, allowing symbolically linked peer dependencies to be found.
Note, however, that using can have other side effects.
Specifically, symbolically linked modules can fail to load if those are linked from more than one location in the dependency tree (Node.js would see those as two separate modules and would attempt to load the module multiple times, causing an exception to be thrown).