← All notes

child_process.spawn starts a subprocess without blocking the event loop

Answer: child_process.spawn() starts a subprocess asynchronously and does not block the Node.js event loop. The node:child_process module also offers exec, execFile, fork, and synchronous counterparts built on spawn or spawnSync. Each asynchronous method returns a ChildProcess object.

spawn, exec, and fork

exec spawns a shell and runs a command in that shell, then passes stdout and stderr to a callback. execFile is similar but, by default, runs the command directly without first spawning a shell. fork starts a new Node.js process and sets up an IPC channel so the parent and child can send messages.

spawnSync, execSync, and execFileSync block the event loop until the child exits. The synchronous counterparts may be more convenient, but the synchronous methods can have significant impact on performance due to stalling the event loop.

stdio pipes

By default the parent and child get pipes for stdin, stdout, and stderr. Those pipes have limited capacity. If the child writes more than the pipe can hold and the parent does not read it, the child can block. Use { stdio: 'ignore' } when the output will not be consumed.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Node.js, Child process, MIT (https://raw.githubusercontent.com/nodejs/node/main/LICENSE). Copyright Node.js contributors; nodejs/node (GitHub), child_process.md (Node.js source docs), MIT (https://raw.githubusercontent.com/nodejs/node/main/LICENSE). Copyright Node.js contributors. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Node.js, Child process, MIT (https://raw.githubusercontent.com/nodejs/node/main/LICENSE). Copyright Node.js contributors; nodejs/node (GitHub), child_process.md (Node.js source docs), MIT (https://raw.githubusercontent.com/nodejs/node/main/LICENSE). Copyright Node.js contributors.

Cite this

Permanent ID: iil:note:nzvm8zrq

iinventedlight. 2026. "child_process.spawn starts a subprocess without blocking the event loop." iinventedlight Library, iil:note:nzvm8zrq, version of 2026-11-17. https://iinventedlight.com/library/notes/node-child-process/. License: CC-BY-4.0.

@misc{iil_note_nzvm8zrq,
  author = {{iinventedlight}},
  title = {{child\_process.spawn starts a subprocess without blocking the event loop}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-17},
  url = {https://iinventedlight.com/library/notes/node-child-process/},
  note = {Permanent ID iil:note:nzvm8zrq. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/node-child-process.md.