mkdirp
Recursive directory creation for Node.js (mkdir -p equivalent). Cross-platform solution for creating nested directory structures that may not exist. Modern versions (v3+) use Node.js native fs.mkdir({ recursive: true }) with a thin wrapper. Also provides a CLI bin for use in npm scripts.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
Path traversal risk if user input is passed without validation. Always sanitize paths before creating directories.
⚡ Reliability
Best When
Cross-platform npm scripts and build tools needing recursive directory creation.
Avoid When
Targeting Node.js 12+ — native fs.mkdir({ recursive: true }) is sufficient without a dependency.
Use Cases
- • Create nested output directories in build scripts: mkdirp('dist/assets/images') creates all intermediate directories
- • Ensure directory exists before writing files in Node.js scripts without explicit existence checks
- • Use in npm scripts for cross-platform mkdir -p behavior: "setup": "mkdirp dist logs tmp"
- • Programmatically create directory trees in Node.js tools and generators
- • Replace platform-specific shell mkdir -p with cross-platform Node.js equivalent
Not For
- • Modern Node.js 12+ projects where fs.mkdir(path, { recursive: true }) is available — mkdirp is a thin wrapper today
- • Complex file system operations — use fs-extra for copy/move/ensureDir comprehensive file system utilities
- • Security-sensitive directory creation — validate paths before calling mkdirp to prevent path traversal
Interface
Authentication
Build tool — no auth needed.
Pricing
ISC licensed open source library.
Agent Metadata
Known Gotchas
- ⚠ mkdirp v3 is ESM-only — CommonJS projects must use mkdirp v2 or native fs.mkdir({ recursive: true })
- ⚠ mkdirp returns undefined (not the path) if the directory already exists — check return value only when you need the first-created path
- ⚠ mkdirpSync is available for synchronous use — async mkdirp() is preferred but sync version exists for compatibility
- ⚠ Windows path separators work correctly but paths with spaces should be quoted in CLI usage
- ⚠ Permission errors are not retried — if directory creation fails due to permissions, the error is thrown immediately
- ⚠ mkdirp does not validate path safety — callers must sanitize paths to prevent creating unintended directory structures
Alternatives
Full Evaluation Report
Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for mkdirp.
Scores are editorial opinions as of 2026-03-06.