Copyright 2025

The Valley of Code

A Flavio Copes project

How to execute a shell command using Node.js
How to execute a shell command using Node.js

Here’s how I ran a shell command from a Node.js script.

First I imported child from child_process:

import * as child from 'node:child_process'

//or 

const child = require('node:child_process')

Then you can call child.exec() like this:

child.exec(`mkdir test`)

Join my AI Workshop !

The Web Development BOOTCAMP cohort starts in February 2026