Skip to content
Tak Tran edited this page Nov 22, 2018 · 4 revisions
  • spawn - "[creates] a new process and we can use it to pass that command any arguments". Has exit, disconnect, error, close, and message event streams that can be hooked into. Each child has standard stdio streams, which we can access using child.stdin, child.stdout, and child.stderr. Does not use a shell by default, but can add it with { stdio: 'inherit', shell: true } in options
  • exec - creates a shell and executes the command. Also it "buffers the command's generated output and passes the whole output value to a callback function (instead of using streams, which is what spawn does)". Can use shell syntax eg, pipes | (although, watch out for security vulnerabilities! eg, ; rm -rf ~)
    • Good if data is small
  • execFile - execute a file without using a shell
  • fork - like spawn, but can received and send messages from the process global

https://medium.freecodecamp.org/node-js-child-processes-everything-you-need-to-know-e69498fe970a

Code examples:

Promise vs Callback exec

CLI

Integration tests

https://medium.com/@zorrodg/integration-tests-on-node-js-cli-part-1-why-and-how-fa5b1ba552fe https://medium.com/@zorrodg/integration-tests-on-node-js-cli-part-2-testing-interaction-user-input-6f345d4b713a

Clone this wiki locally