Skip to main content

Command Palette

Search for a command to run...

Today's npm package: is-directory

Published
1 min read

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
}

More from this blog

P

Pankaj Patel - @heypankaj_

63 posts

Sharing my learnings and thoughts on Blogging, Personal Branding and Programming