-
Notifications
You must be signed in to change notification settings - Fork 0
NodeJS
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". Hasexit,disconnect,error,close, andmessageevent streams that can be hooked into. Each child has standardstdiostreams, which we can access usingchild.stdin,child.stdout, andchild.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 whatspawndoes)". 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- likespawn, but can received and send messages from theprocessglobal
https://medium.freecodecamp.org/node-js-child-processes-everything-you-need-to-know-e69498fe970a
Code examples:
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