Package Exports
- mk-dirs
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (mk-dirs) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
mk-dirs 
A tiny (420B) 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!
Important: Requires Node 8.x or later – uses
asyncfunctions.
Available in these formats:
- ES Module:
dist/index.mjs - CommonJS:
dist/index.js
Note:
Are you using Node.js 10.12 or later?
If so, You should use the built-infs.mkdirinstead!
const { mkdir } = require('fs');
const { promisify } = require('util');
const mkdirp = promisify(mkdir);
function mkdirs(str, opts={}) {
return mkdirp(str, { ...opts, recursive:true });
}Install
$ npm install --save mk-dirsUsage
$ pwd
# /Users/hello/world
$ tree
# .import mkdirs from 'mk-dirs';
import { resolve } from 'path';
// Async/await
try {
let output = await mkdirs('foo/bar/baz');
console.log(output); //=> "/Users/hello/world/foo/bar/baz"
} catch (err) {
//
}
// Promises
mkdirs('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 mkdirs('hola/mundo', { cwd: dir });
//=> "/Users/hello/world/foo/bar/hola/mundo"$ tree
# .
# └── foo
# └── bar
# └── baz
# └── hola
# └── mundoAPI
mkdir(path, options={})
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.
path
Type: String
The directory to create.
options.cwd
Type: String
Default: .
The directory to resolve your path from.
Defaults to the process.cwd() – aka, the directory that your command is run within.
options.mode
Type: Number
Default: 0o777 & (~process.umask())
The directory permissions to set.
Important: Must be in octal format!
Comparisons
Versus make-dir
mk-dirsis slightly faster- ...has zero dependencies
- ...does offer
cwdoption - ...does not re-wrap an existing Promise
- ...does not ship with a
syncmethod - ...does not allow custom
fsoption
Versus mkdirp
mk-dirsis much faster- ...has zero dependencies
- ...is a Promise-based API
- ...is
async/awaitready! - ...is tested on macOS, Linux, and Windows
- ... has fixes for
mkdirpissues: #96, #70, #66 - ...includes a
cwdoption - ...does not ship with a
syncmethod - ...does not allow custom
fsoption - ...does not bundle a CLI runtime
Related
premove– A tiny (247B) utility to remove items recursively
License
MIT © Luke Edwards