Skip to main content

Command Palette

Search for a command to run...

Today's npm package: is-directory

Updated
โ€ข1 min read
P

I am developer from India currently based in Berlin, Germany.

I am very interested in Design, though I don't design ๐Ÿ˜‰ I take care of it while making my apps.

Photography, videography and having random conversation over beer are my activities of spare time. Timelapses and hyperlapses make me wonder all the time ๐Ÿ˜Š

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
}
C

Can't we do that with the fs module in Node.js already? ๐Ÿค”

2
P

Yes we can; and apparently the package is using fs under the hood

https://github.com/jonschlinkert/is-directory/blob/master/index.js

More from this blog

P

Pankaj Patel - @heypankaj_

63 posts

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