Created
September 14, 2023 07:17
-
-
Save neos1803/30b315437637369249a53ae4fc4214d5 to your computer and use it in GitHub Desktop.
Making directory the async way
This file contains 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 { stat, mkdir } = require('fs/promises'); | |
/** Start of creating directory */ | |
const directory = `your path like directory`; | |
await stat(directory) | |
.then(() => { | |
console.log(`Directory: ${dir} exist`); | |
return true | |
}) | |
.catch(async (error) => { | |
if (error?.code === 'ENOENT') { | |
await mkdir(directory, { recursive: true }); | |
console.log(`Success creating new directory: ${directory}`); | |
return true | |
} | |
throw error; | |
}) | |
/** End of creating directory */ | |
// Do the rest of related uploading process |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment