Node.js module
child_process
The 'node:child_process' module enables spawning and controlling subprocesses from Node.js. It supports synchronous and asynchronous execution via exec, execFile, spawn, and fork functions.
Child processes can inherit stdio, communicate via IPC channels, and return exit codes. This module is essential for leveraging external commands, implementing parallel work, and managing worker processes.
Works in Bun · notes
Core functionality works. The Stream class is not exported. IPC cannot send socket handles between processes; Node.js <> Bun IPC can be used with JSON serialization. Some process properties are missing.
Functions 7
- child_process.exec()
Spawns a shell then executes the
commandwithin that shell, buffering any generated output. - child_process.execFile()
The
child_process.execFile()function is similar to exec except that it does not spawn a shell by default. - child_process.execFileSync()
The
child_process.execFileSync()method is generally identical to execFile with the exception that the method will not return until the child process has fully closed. - child_process.execSync()
The
child_process.execSync()method is generally identical to exec with the exception that the method will not return until the child process has fully closed. - child_process.fork()
The
child_process.fork()method is a special case of spawn used specifically to spawn new Node.js processes. - child_process.spawn()
The
child_process.spawn()method spawns a new process using the givencommand, with command-line arguments inargs. - child_process.spawnSync()
The
child_process.spawnSync()method is generally identical to spawn with the exception that the function will not return until the child process has fully closed.
Classes 1
- class child_process.ChildProcess
Instances of the
ChildProcessrepresent spawned child processes.
Interfaces 32
- interface ChildProcessByStdio
Instances of the
ChildProcessrepresent spawned child processes. - interface ChildProcessEventMap
- interface ChildProcessWithoutNullStreams
Instances of the
ChildProcessrepresent spawned child processes. - interface CommonExecOptions
- interface CommonOptions
- interface CommonSpawnOptions
- interface Control
The
EventEmitterclass is defined and exposed by thenode:eventsmodule. - interface ExecException
- interface ExecFileOptions
- interface ExecFileOptionsWithBufferEncoding
- interface ExecFileOptionsWithStringEncoding
- interface ExecFileSyncOptions
- interface ExecFileSyncOptionsWithBufferEncoding
- interface ExecFileSyncOptionsWithStringEncoding
- interface ExecOptions
- interface ExecOptionsWithBufferEncoding
- interface ExecOptionsWithStringEncoding
- interface ExecSyncOptions
- interface ExecSyncOptionsWithBufferEncoding
- interface ExecSyncOptionsWithStringEncoding
- interface ForkOptions
- interface MessageOptions
- interface MessagingOptions
- interface ProcessEnvOptions
- interface PromiseWithChild
- interface SpawnOptions
- interface SpawnOptionsWithoutStdio
- interface SpawnOptionsWithStdioTuple
- interface SpawnSyncOptions
- interface SpawnSyncOptionsWithBufferEncoding
- interface SpawnSyncOptionsWithStringEncoding
- interface SpawnSyncReturns