How to execute a shell script with Node.js

July 1, 2020

You can execute a shell script with Node.js without even installing any packages.

const { spawn } = require('child_process')

spawn('git clone && cd potion', {
  shell: true

The shell: true option allows you to execute any command, like you would on the command line.

For more options, like specifying which directory to execute the command in, check out the official Node.js documentation.

Follow my twitter (@benborgers) to see the work-in-progress of coding projects Iā€™m working on!