mkdir-parents - npm
mkdir-parents is a function like mkdir -p
.
This function returns promise, async/await ready,
also yieldable, thunkified, promisified, useful with aa
or co
.
$ npm install mkdir-parents
const mkdirParents = require('mkdir-parents');
- dir - directory path name
- [mode] - {optional} permission
- [callback] - {optional} function callback(err)
- retuns - promise, thunk for
aa
orco
. returns undefined if callback is specified.
- dir - directory path name
- [mode] - {optional} permission
// require dependencies
const mkdirParents = require('mkdir-parents');
// async await style function
async function main() {
const dir = '/tmp/deep/dir';
const mode = parseInt('0777', 8);
try {
await mkdirParents(dir, mode);
console.log(dir + ' created with perm 0' + mode.toString(8));
} catch (err) {
console.log(dir + ' cant created with status ' + err);
}
}
main();
// require dependencies
const mkdirParents = require('mkdir-parents');
const dir = '/tmp/deep/dir';
const mode = parseInt('0777', 8);
mkdirParents(dir, mode)
.then(() => console.log(dir + ' created with perm 0' + mode.toString(8)))
.catch(err => console.log(dir + ' cant created with status ' + err));
// require dependencies
const mkdirParents = require('mkdir-parents');
const aa = require('aa');
// aa with generator
aa(function *() {
var dir = '/tmp/deep/dir';
var mode = parseInt('0777', 8);
try {
yield mkdirParents(dir, mode);
console.log(dir + ' created with perm 0' + mode.toString(8));
} catch (err) {
console.log(dir + ' cant created with status ' + err);
}
}).then(function () {});
// require dependencies
var mkdirParents = require('mkdir-parents');
var dir = '/tmp/deep/dir';
var mode = parseInt('0777', 8);
mkdirParents(dir, mode, function (err) {
if (err) {
console.log(dir + ' cant created with status ' + err);
} else {
console.log(dir + ' created with perm 0' + mode.toString(8));
}
});
// require dependencies
var mkdirParents = require('mkdir-parents');
var dir = '/tmp/deep/dir';
var mode = parseInt('0777', 8);
mkdirParents(dir, mode)(function (err) {
if (err) {
console.log(dir + ' cant created with status ' + err);
} else {
console.log(dir + ' created with perm 0' + mode.toString(8));
}
});
// require dependencies
var mkdirParentsSync = require('mkdir-parents').sync;
var dir = '/tmp/deep/dir';
var mode = parseInt('0777', 8);
try {
mkdirParentsSync(dir, mode);
console.log(dir + ' created with perm 0' + mode.toString(8));
} catch (err) {
console.log(dir + ' cant created with status ' + err);
}
MIT