Skip to content

Instantly share code, notes, and snippets.

View PythonCoderAS's full-sized avatar

PythonCoderAS PythonCoderAS

  • New York City
  • 08:53 (UTC -04:00)
View GitHub Profile
@PythonCoderAS
PythonCoderAS / spawn vs child_process.md
Last active August 5, 2022 23:18 — forked from devarajchidambaram/spawn vs child_process
Difference between spawn and exec functions of child_process

Difference between spawn and exec functions of child_process

The Node.js Child Processes module (child_process) has two functions spawn and exec, using which we can start a child process to execute other programs on the system. Those new to child_process may wonder why there are two functions to do the same thing, and which one they should use. I'll explain the differences between spawn and exec to help you decide when to use what.

The most significant difference between child_process.spawn and child_process.exec is in what they return - spawn returns a stream and exec returns a buffer.

child_process.spawn returns an object with stdout and stderr streams. You can tap on the stdout stream to read data that the child process sends back to Node. stdout being a stream has the "data", "end", and other events that streams have. spawn is best used to when you want the child process to return a large amount of data to Node - image processing, reading binary data etc.

child_process.spawn is "asynchronously async

@PythonCoderAS
PythonCoderAS / gist:c0923bfea82009779acbdca8ad74c772
Last active May 10, 2022 23:57 — forked from rxaviers/gist:7360908
Complete list of github markdown emoji markup

People

:bowtie: :bowtie: 😄 :smile: 😆 :laughing:
😊 :blush: 😃 :smiley: ☺️ :relaxed:
😏 :smirk: 😍 :heart_eyes: 😘 :kissing_heart:
😚 :kissing_closed_eyes: 😳 :flushed: 😌 :relieved:
😆 :satisfied: 😁 :grin: 😉 :wink:
😜 :stuck_out_tongue_winking_eye: 😝 :stuck_out_tongue_closed_eyes: 😀 :grinning:
😗 :kissing: 😙 :kissing_smiling_eyes: 😛 :stuck_out_tongue:
<reddit-user-info status="public" date="YYYY-MM-DD" timezone="UTC" username="USERNAME">
<karma posts="postkarma" comments="commentkarma" total="totalkarma"/>
<subreddit-catalog>
<subreddit name="name" status="status" link="https://www.reddit.com/r/Example/">
<modstatus permissions="none"/>
</subreddit>
<!-- A typical new user might visit around 10-20 subs. A typical old user would have visited around 50-70 subs. -->
<!-- A typical mod might mod 1-5 subs. Older mods might mod 5-10 subs. Experinced modders might mod 10-20 subs. AutoMod mods every single subreddit.-->
</subreddit-catalog>
</reddit-user-info>