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 install mkdirp
yarn add mkdirp
pnpm add mkdirp
Import
import { mkdirp } from 'mkdirp';Quick Example
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
| Package | mkdirp |
| Category | File System |
| Weekly Downloads | 30M+ |
| License | MIT |
| Install | npm install mkdirp |
Related Packages
fs-extra is a drop-in replacement for Node.js's built-in fs module that adds additional file system …
rimraf is a Node.js implementation of the Unix rm -rf command, providing cross-platform recursive di…
tmp is a library for creating temporary files and directories in Node.js that provides automatic cle…
glob is a library for matching files using glob patterns — the wildcard syntax familiar from shell c…
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.