Ben Borgers

⇢ Twitter

How to execute a shell script with Node.js

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.

--

Last updated January 24, 2021