How to execute a shell script with Node.js

January 24, 2021

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.

A quick favor: was anything I wrote incorrect or misspelled, or do you still have questions? Please use this form to let me know or ask for help!

Loading...