NodeJS Executing files or commands with Child Processes
Spawning a new process to execute a command
To spawn a new process in which you need unbuffered output (e.g. long-running processes which might print output over a period of time rather than printing and exiting immediately), use child_process.spawn().
This method spawns a new process using a given command and an array of arguments. The return value is an instance of ChildProcess, which in turn provides the stdout and stderr properties. Both of those streams are instances of stream.Readable.
The following code is equivalent to using running the command ls -lh /usr.
Another example command: