NODEJS Contents

Child Process

Child processes allow isolation and execution of external programs, but they introduce overhead and require careful resource management.

On this page

What Child Processes Provide

Child processes allow running shell commands or separate Node processes. They provide isolation and can leverage system-level tools.

Example

import { spawn } from 'node:child_process';

const ls = spawn('ls', ['-lh']);
ls.stdout.on('data', data => {
  console.log(data.toString());
});

When to Use

  • Running external binaries (ffmpeg, imagemagick)
  • Sandboxing risky computations
  • Legacy integration

Production Risks

  • Zombie processes
  • Unbounded process spawning
  • Memory duplication

Prefer worker threads for CPU tasks inside Node. Use child processes when you need OS-level separation or external tooling.