Hibou57 Hibou57 - 10 days ago 5
Node.js Question

Node.js’s spawn, exec, options and encoding

Node.js’s

child_process.exec
options
argument has an
encoding
member, while the
options
argument of
child_process.spawn
don’t, according to my API documentation (Node.js up to date docset).

Why this difference?

Note: I'm new to Node.js

Answer

spawn() doesn't have an encoding option because it doesn't buffer any data, whereas exec() does. You can call .setEncoding() on any of the child process's Readable streams (e.g. stdout and/or stderr) however and those streams will emit strings of that encoding.