Execute a command line binary with Node.js

Posted by Ramesh Singh | Updated on

In you want to execute a command line binary with Node.js. For even newer version of Node.js (v8.1.4), the events and calls are similar or identical to older versions, but it’s encouraged to use the standard newer language features. Examples:

For buffered, non-stream formatted output (you get it all at once), use child_process.exec:

You can also use it with Promises:

If you wish to receive the data gradually in chunks (output as a stream), use child_process.spawn:

If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers