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.
Subscribe to my newsletter!
A weekly round-up of new blog posts and updates to projects I’m working on.