📂
File System30M+/wkMIT

mkdirp

mkdirp is a Node.js utility that recursively creates directories, equivalent to mkdir -p in Unix. Given a path like 'a/b/c/d', mkdirp creates all necessary pare

Installation

npm
npm install mkdirp
yarn
yarn add mkdirp
pnpm
pnpm add mkdirp

Import

ESM
import { mkdirp } from 'mkdirp';

Quick Example

usage
import { mkdirp } from 'mkdirp';

await mkdirp('dist/assets/images');
await mkdirp('logs/2024/03');

// Returns the first created directory
const made = await mkdirp('/tmp/a/b/c');

About mkdirp

mkdirp is a Node.js utility that recursively creates directories, equivalent to mkdir -p in Unix. Given a path like 'a/b/c/d', mkdirp creates all necessary parent directories that do not already exist. The package handles edge cases including race conditions when multiple processes try to create the same directory simultaneously, platform-specific path separators, and permission handling. mkdirp provides both promise-based async and synchronous APIs, returning the path of the first directory that was actually created. Version 2+ of mkdirp uses Node.js's native fs.mkdir with recursive option when available, while maintaining backward compatibility with the callback API from earlier versions. The package also includes a CLI (npx mkdirp some/nested/dir) for use in npm scripts. While Node.js 10.12+ supports fs.mkdir with the recursive option natively, mkdirp provides a cleaner API, better error handling, and compatibility with older Node.js versions. mkdirp is one of the most depended-upon packages in npm, used in build scripts, test setup, file processing pipelines, and any scenario where directories need to be created programmatically. The package name has become a common verb in the Node.js community — developers say 'mkdirp the output folder.'

Quick Facts

Packagemkdirp
CategoryFile System
Weekly Downloads30M+
LicenseMIT
Installnpm install mkdirp

Related Packages

Browse npm Packages by Category

Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.