Running Other Programs
child_process runs commands. execSync returns the output, spawn streams it. Never pass user input to a shell command.
Example
const { execSync, spawnSync } = require('node:child_process');
console.log(execSync('echo hello').toString().trim());
const r = spawnSync('node', ['-e', 'console.log(1 + 1)']);
console.log(r.stdout.toString().trim(), r.status);Result
hello 2 0
Exercise
Run a command.
("echo hi")Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.