
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
A tiny (381B to 419B) utility to make a directory and its parents, recursively
A tiny (381B to 419B) utility to make a directory and its parents, recursively
This is a Promise-based utility that recursively creates directories. It's effectively mkdir -p for Node.js.
This module is a fast and lightweight alternative to mkdirp. Check out Comparisons for more info!
Notice: Node v10.12.0 includes the
recursiveoption forfs.mkdirandfs.mkdirSync.
const { mkdir } = require('fs');
const { promisify } = require('util');
const mkdirp = promisify(mkdir);
function mkdirs(str, opts={}) {
return mkdirp(str, { ...opts, recursive:true });
}
$ npm install --save mk-dirs
There are two "versions" of mk-dirs available:
Node.js: >= 8.x
Size (gzip): 419 bytes
Availability: CommonJS, ES Module
This is the primary/default mode. It makes use of async/await and util.promisify.
Node.js: >= 6.x
Size (gzip): 381 bytes
Availability: CommonJS, ES Module
This is the opt-in mode, ideal for scenarios where async usage cannot be supported.
In order to use it, simply make the following changes:
-import { mkdir } from 'mk-dirs';
+import { mkdir } from 'mk-dirs/sync';
$ pwd
# /Users/hello/world
$ tree
# .
import { mkdir } from 'mk-dirs';
import { resolve } from 'path';
// Async/await
try {
let output = await mkdir('foo/bar/baz');
console.log(output); //=> "/Users/hello/world/foo/bar/baz"
} catch (err) {
//
}
// Promises
mkdir('foo/bar/baz').then(output => {
console.log(output); //=> "/Users/hello/world/foo/bar/baz"
}).catch(err => {
//
});
// Using `cwd` option
let dir = resolve('foo/bar');
await mkdir('hola/mundo', { cwd: dir });
//=> "/Users/hello/world/foo/bar/hola/mundo"
$ tree
# .
# └── foo
# └── bar
# └── baz
# └── hola
# └── mundo
Returns: Promise<String>
Returns a Promise, which resolves with the full path (string) of the created directory.
Any file system errors will be thrown and must be caught manually.
Type: String
The directory to create.
Type: String
Default: .
The directory to resolve your path from.
Defaults to the process.cwd() – aka, the directory that your command is run within.
Type: Number
Default: 0o777 & (~process.umask())
The directory permissions to set.
Important: Must be in octal format!
Versus make-dir
mk-dirs is slightly fastercwd optionsync methodfs optionVersus mkdirp
mk-dirs is much fasterasync/await ready!mkdirp issues: #96, #70, #66cwd optionsync methodfs optiontotalist - A tiny (195B to 224B) utility to recursively list all (total) files in a directoryescalade - A tiny (183B) and fast utility to ascend parent directoriespremove – A tiny (247B) utility to remove items recursivelyMIT © Luke Edwards
FAQs
A tiny (381B to 419B) utility to make a directory and its parents, recursively
The npm package mk-dirs receives a total of 30,524 weekly downloads. As such, mk-dirs popularity was classified as popular.
We found that mk-dirs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.