There's a package called mkdirp; https://npmjs.org/package/mkdirp should probably use that instead of writing this code ourselves