Hibou57 Hibou57 - 1 year ago 171
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 Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download