Skip to content

Instantly share code, notes, and snippets.

@neos1803
Created September 14, 2023 07:17
Show Gist options
  • Save neos1803/30b315437637369249a53ae4fc4214d5 to your computer and use it in GitHub Desktop.
Save neos1803/30b315437637369249a53ae4fc4214d5 to your computer and use it in GitHub Desktop.
Making directory the async way
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