Creating Recursive Directories in Node.js like mkdir -p

January 15, 2023

Ever wanted to create recursive directories with you Node.js code?

Here is how to do it without any dependencies

import { mkdir } from 'fs/promises';
// const { mkdir } = require('fs/promises') // CommonJS

const createRecursiveDir = async filepath => mkdir(filepath, { recursive: true })

Happy nested directories!

👋 I'm Ashik Nesin • Principal Software Engineer 👨‍💻• I write about web development and share insights into the behind-the-scenes of the projects that I'm building.

© 2023 Nesin Technologies LLP