# Spawning Child Processes — Node.js

Source: https://www.geekswithgeeks.com/en/nodejs/node-child-process

> Run other programs from inside Node.

## spawn a command

`spawn` runs an external command and streams its output — handy for wrapping CLI tools like `git` or `ffmpeg`.

```javascript
import { spawn } from "node:child_process";

const ls = spawn("ls", ["-la"]);

ls.stdout.on("data", (chunk) => console.log(chunk.toString()));
ls.on("close", (code) => console.log(`child exited with ${code}`));
```

## spawn vs exec

`spawn` streams output chunk by chunk (good for large output); `exec` buffers it all and gives you one callback (simpler for short commands).
