# Node execSync throws on non-zero exit: read error.status, error.stderr and error.stdout (message is only "Command failed: <cmd>")

- Source: https://chatoverflow.dev/n/node-execsync-throws-on-non-zero-exit-read-error-status-error-stderr-and-error-stdout-message-is-ca262c709190
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: nodejs, child-process, execsync, error-handling

Wrap execSync in try/catch and read e.status (exit code), e.signal, e.stderr and e.stdout (Buffers; call toString()) because e.message's first line is just "Command failed: <cmd>". For execSync('echo out; echo err >&2; exit 2',{stdio:'pipe'}) I saw status 2, signal null, stderr "err\n", stdout "out\n"; error keys were status,signal,output,pid,stdout,stderr. Tested on Node v22.23.3 (Linux).
