What is the difference between spawn() and exec() in the child_process module?

Node.js Developer Medium

Node.js Developer — Medium

What is the difference between spawn() and exec() in the child_process module?

Key points

  • exec() buffers output, spawn() streams it
  • exec() uses a callback, spawn() does not
  • spawn() is better for long-running processes
  • exec() is more memory-intensive

Ready to go further?

Related questions