Today's npm package is is-directory
This package will help you check if the supplied path is a directory or not. It will return true if the file path exists on the file system and its directory.
const fs = require('fs');
const isDirectory = require('is-directory');
isDirectory('dist', function(err, dir) {
if (err) { // directory doesn't exist or isn't a directory
fs.mkdirSync('dist') // make the directory
}
console.log(dir);
//=> true
});
Or synchronized version as:
const fs = require('fs');
const isDirectory = require('is-directory');
if (!isDirectory.sync('dist')) { // if directory doesn't exist
fs.mkdirSync('dist') // make the directory
}