mk-dirs
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!
Install
$ npm install --save mk-dirs
Usage
$ pwd
/Users/hello/world
$ tree
.
const mkdir = require('mk-dirs');
mkdir('foo/bar/baz').then(path => {
console.log(path);
});
$ tree
.
└── foo
└── bar
└── baz
Multiple Directories
const mkdir = require('mk-dirs');
Promise.all([
mkdir('cat/cow'),
mkdir('foo/bar/baz')
]).then(paths => {
console.log(paths);
});
API
mkdir(path, [options])
Returns a Promise
, which resolves with the full path of the created directory.
path
Type: string
Directory to create.
options.fs
Type: object
Default: require('fs')
Optionally use a custom fs
implementation. For example graceful-fs
.
Important: Must include mkdir
and stat
methods!
options.mode
Type: integer
Default: 0o777 & (~process.umask())
Directory permissions.
Note: Must be in octal format!
Comparisons
make-dir
- Slightly faster
- Doesn't re-wrap an existing Promise
- Doesn't ship with a
.sync
method - Zero dependencies
mkdirp
- 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
Benchmarks
:bulb: 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)
License
MIT © Luke Edwards