Skip to content

Instantly share code, notes, and snippets.

@ivoputzer
Last active September 6, 2016 12:52
Show Gist options
  • Save ivoputzer/13b02b288795e1249ea890eeca17b5f6 to your computer and use it in GitHub Desktop.
Save ivoputzer/13b02b288795e1249ea890eeca17b5f6 to your computer and use it in GitHub Desktop.
[ES6] recursive mkdir-sync in node.js
#!/usr/bin/env node
const {mkdirSync:mkdir} = require('fs')
const {dirname} = require('path')
function mkdirp(path, mode = 0777){
try {
mkdir(path, mode)
} catch({errno}) {
if (-2 !== errno) return // enoent
mkdirp(dirname(path), mode)
mkdirp(path, mode)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment