Make a directory and its parents, if necessary.
This is a fast and lightweight alternative to mkdirp
. It's also heavily inspired by make-dir
.
Check out Comparisons for more info!
$ npm install --save mk-dirs
$ pwd
/Users/hello/world
$ tree
.
const mkdir = require('mk-dirs');
mkdir('foo/bar/baz').then(path => {
console.log(path);
//=> '/Users/hello/world/foo/bar/baz'
});
$ tree
.
└── foo
└── bar
└── baz
const mkdir = require('mk-dirs');
Promise.all([
mkdir('cat/cow'),
mkdir('foo/bar/baz')
]).then(paths => {
console.log(paths);
//=> [ '/Users/hello/world/cat/cow', '/Users/hello/world/foo/bar/baz' ]
});
Returns a Promise
, which resolves with the full path of the created directory.
Type: string
Directory to create.
Type: object
Default: require('fs')
Optionally use a custom fs
implementation. For example graceful-fs
.
Important: Must include
mkdir
andstat
methods!
Type: integer
Default: 0o777 & (~process.umask())
Directory permissions.
Note: Must be in octal format!
- Slightly faster
- Doesn't re-wrap an existing Promise
- Doesn't ship with a
.sync
method - Zero dependencies
- Promise API (Async/await ready!)
- Fixes many
mkdirp
issues: #96 #70 #66 - CI-tested on macOS, Linux, and Windows
- Doesn't ship with a
.sync
method - Doesn't bundle a CLI
💡 Please consider that these benchmarks are largely affected by System behavior! In other words, the time it takes your OS to create a directory is never consistent.
mk-dirs
--> 3,768 ops/sec ±1.95% (72 runs sampled)
make-dir
--> 3,527 ops/sec ±4.28% (64 runs sampled)
mkdirp
--> 3,305 ops/sec ±2.56% (67 runs sampled)
MIT © Luke Edwards