Skip to content

Child Process

Medium — good to knowBackend

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."

Made with passive-aggressive love by manoga.digital. Powered by Claude.