Ben Borgers

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 https://github.com/benborgers/potion && 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.

More blog posts

Subscribe to my newsletter for a monthly round-up of new blog posts and projects Iā€™m working on!

Twitter ↗ RSS feed ↗