Created
October 23, 2018 10:44
-
-
Save bwinant/0407d4ae620f230c8252f8fbd65bb162 to your computer and use it in GitHub Desktop.
mkdirs in Node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const path = require('path'); | |
const dirToCreate; | |
const initDir = path.isAbsolute(dirToCreate) ? path.sep : ''; | |
dirToCreate.split(path.sep).reduce((parentDir, childDir) => { | |
const curDir = path.resolve(parentDir, childDir); | |
if (!fs.existsSync(curDir)) { | |
fs.mkdirSync(curDir); | |
} | |
return curDir; | |
}, initDir); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment