Search code examples
javascriptnode.jsecmascript-6child-process

{ Spawn } vs spawn


I came across this while learning about child processes:

const {spawn} = require('child_process');

My question is, what is the difference between the above and this:

const spawn = require('child_process');

Solution

  • The 1st extracts spawn variable from inside child_proccess. This only unpack value of spawn from child_proccess instead of the whole module.

    The 2nd sets spawn variable the entire child_process module (as a whole).

    read more on Destructuring assignment