Tsallaka zuwa abun ciki
Justice Tech School

child_process

execSync and spawn run other programs. Never pass raw user input to a shell.

Example
const { execSync, spawnSync } = require("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

Why avoid shell input?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.