Pankaj Patel
Pankaj Patel

Follow

Pankaj Patel

Follow

Today's npm package: is-directory

Pankaj Patel's photo
Pankaj Patel
ยทJun 8, 2021ยท

1 min read

Play this article

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
}
ย 
Share this