Child Process
ELI5 — The Vibe Check
A child process is when your Node.js app spawns a completely separate process to do work. It's like delegating a task to a coworker in a different room — they have their own resources, their own memory, and you communicate by passing messages back and forth.
Real Talk
The child_process module in Node.js allows spawning separate OS processes from the main application. It provides exec, spawn, fork, and execFile methods for running shell commands, scripts, or other Node.js modules in isolated processes. Communication happens via IPC channels, stdin/stdout, or signals.
Show Me The Code
const { exec, spawn } = require('child_process');
// Simple command
exec('ls -la', (err, stdout) => console.log(stdout));
// Streaming output
const child = spawn('ffmpeg', ['-i', 'input.mp4', 'output.webm']);
child.stdout.on('data', (data) => console.log(data.toString()));
When You'll Hear This
"We spawn a child process for video encoding so it doesn't block the server." / "Use fork() for child processes that need to communicate with the parent via IPC."
Related Terms
Concurrency
Concurrency is juggling multiple tasks at once — not necessarily at the exact same instant, but switching between them fast enough that they all seem to be...
Process
A process is a full running program with its own isolated chunk of memory.
Worker Threads
Worker Threads let Node.js actually use more than one CPU core. Normally Node is single-threaded — it can only do one heavy calculation at a time.