Registry / devops / mk-dirs

mk-dirs

JSON →
library3.0.0jsnpmunverified

mk-dirs is a minimalistic, Promise-based utility designed for recursively creating directories in Node.js, functioning as an `mkdir -p` equivalent. Currently stable at version 3.0.0, it differentiates itself by being exceptionally lightweight (381B to 419B gzipped) and having zero external dependencies, offering a faster alternative to packages like `mkdirp` and `make-dir`. It provides both an asynchronous (default) and a synchronous opt-in mode, catering to different application needs and Node.js versions (>=8.x for async, >=6.x for sync). While Node.js v10.12.0+ includes native `fs.mkdir` with a `recursive` option, `mk-dirs` maintains its value through a consistent, promise-based API and `cwd` option. Its release cadence is not explicitly stated but typically follows a "release when needed" pattern for such focused utilities.

npm install mk-dirs
INSTALL
IMPORT
SIG · MK-DIRS
M
mk-dirs
devopsjavascriptv3.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

mkdir (async ESM)
import { mkdir } from 'mk-dirs';
import mkdir from 'mk-dirs';
This is the primary asynchronous API for ES Modules. It is a named export, not a default export.
mkdir (async CJS)
const { mkdir } = require('mk-dirs');
const mkdir = require('mk-dirs');
This is the primary asynchronous API for CommonJS environments. Ensure you destructure the 'mkdir' function from the module object.
mkdir (sync ESM)
import { mkdir } from 'mk-dirs/sync';
import { mkdir } from 'mk-dirs';
For synchronous operation, you must import specifically from `mk-dirs/sync`. Importing from the default path will yield the asynchronous API.

Demonstrates asynchronous recursive directory creation using both async/await and Promise chaining, including the use of a custom `cwd` option.

import { mkdir } from 'mk-dirs'; import { resolve } from 'path'; async function createDirectories() { const baseDir = process.cwd(); console.log(`Current working directory: ${baseDir}`); // Async/await usage try { let output1 = await mkdir('foo/bar/baz'); console.log(`Created directory (async/await): ${output1}`); // Using `cwd` option let customCwd = resolve(baseDir, 'temp/custom'); let output2 = await mkdir('alpha/beta', { cwd: customCwd }); console.log(`Created directory with custom cwd: ${output2}`); } catch (err) { console.error('Error during async/await mkdir:', err); } // Promise chain usage mkdir('another/path/deeply') .then(output => { console.log(`Created directory (Promise chain): ${output}`); }) .catch(err => { console.error('Error during Promise chain mkdir:', err); }); } createDirectories();
Debug
Known issues
gotchaNative Node.js support for recursive directory creation makes external libraries like mk-dirs potentially redundant for simple use cases. Node.js v10.12.0 and above include `fs.mkdir` and `fs.mkdirSync` with a `{ recursive: true }` option, offering built-in functionality.
fix
Consider using Node.js's native `fs.promises.mkdir` or `fs.mkdirSync` with `{ recursive: true }` for new projects or when migrating older code, unless `mk-dirs`'s specific features (like the 'cwd' option) are required.
affects: >=10.12.0 (Node.js)
gotchaThe synchronous API requires an explicit import path: `mk-dirs/sync`. Importing from the default `mk-dirs` will always provide the asynchronous, Promise-based API.
fix
To use the synchronous version, ensure your import statement is `import { mkdir } from 'mk-dirs/sync';` for ESM or `const { mkdir } = require('mk-dirs/sync');` for CommonJS.
affects: >=3.0.0
gotchaDirectory permissions (`options.mode`) must be specified in octal format, not decimal. Incorrectly formatted modes can lead to unexpected permissions or errors.
fix
Always prefix octal numbers with '0o', e.g., `0o755` instead of `755`. The default is `0o777 & (~process.umask())`.
affects: >=3.0.0
Errors
Common errors & fixes
TypeError: (0 , mk_dirs__WEBPACK_IMPORTED_MODULE_0__.mkdir) is not a function
Attempting to call the module object directly, or incorrect destructuring of the named 'mkdir' export in ESM or CJS.
fix
For ESM, ensure you use `import { mkdir } from 'mk-dirs';`. For CommonJS, use `const { mkdir } = require('mk-dirs');`.
UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch().
The `mkdir` function returns a Promise, and its rejection was not handled by an `await` within a `try/catch` block or a `.catch()` method.
fix
Wrap async calls in a `try...catch` block (`await mkdir(...);`) or chain a `.catch(err => { /* handle error */ })` to the Promise return.
Error: EPERM: operation not permitted, mkdir '/path/to/dir'
Insufficient file system permissions for the current user to create directories at the specified path, or an incorrect `mode` option was applied.
fix
Run the process with appropriate user permissions, verify the target directory is writable, or ensure the `mode` option is correctly specified in octal format (e.g., `0o777`).
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
mk-dirs — npm install mk-dirs · libregistry