Skip to content

Instantly share code, notes, and snippets.

@vjandrei
Last active August 29, 2019 05:01
Show Gist options
  • Save vjandrei/781b2edd1ce07f60548cf650a99cd6dd to your computer and use it in GitHub Desktop.
Save vjandrei/781b2edd1ce07f60548cf650a99cd6dd to your computer and use it in GitHub Desktop.
create folder and single file on to it
const path = require('path');
const mkdirp = require('mkdirp-promise');
const fs = require('fs-extra')
let dirs = [
"foldername1",
"foldername2",
"foldername3"
];
const file = 'json.txt'
const makeAllDirs = (root, list) => {
return list.reduce((p, item) => {
return p.then(() => {
return mkdirp(path.join(root, item));
});
}, Promise.resolve());
}
makeAllDirs(__dirname, dirs).then(() => {
// all done here
dirs.forEach(function(element) {
console.log(element);
fs.outputFile('./' + element + '/' + file, 'hello!', err => {})
});
}).catch(err => {
// error here
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment