concurrency-scalingAnswer last reviewed July 2026

Node gives you spawn, exec, execFile, and fork. What's actually different between them?

Good candidates know all four APIs wrap spawn, and can reason from stdio mechanics to the full-pipe deadlock and the kill that leaves orphans behind.

What an AI-prepared candidate might say

They all run another program, the differences are mostly ergonomics. spawn is the base one. It starts the process and gives you streams for stdin, stdout, and stderr, so it fits long-running processes or big output. exec runs your command through a shell and buffers the entire output, then hands it to a callback. That works for short commands with small output, because I'm pretty sure the buffer has a size cap on it. execFile is basically exec without the shell, it runs the binary directly with an argument array, so it's faster and safer with untrusted input. And fork is spawn specialized for Node scripts. It launches a new Node process and sets up an IPC channel, so parent and child can exchange messages with send and the 'message' event. That's the primitive sitting under cluster and process pools.

Senior
Locked

One primitive, three wrappers. Where the shell sneaks in, what maxBuffer really caps, how fork wires up IPC, and how the stdio modes decide who feels backpressure.

Unlock the depth
Staff
Locked

The stalled-child postmortem, killing whole process trees without leaving orphans, and the review habits that keep exec injection out of a codebase.

Unlock the depth
Follow-up chain
Node gives you spawn, exec, execFile, and fork. What's actually different between them? | NodeBook