check if a descriptor is a directory.

  • isdir

Downloads in past


502.0.19 years ago9 years agoMinified + gzip package size for isdir in KB


Build Status Test Coverage Code Climate !Node.js Versionnode-version-imagenode-version-url !NPM Versionnpm-imagenpm-url Dependency Status
isdir checks if a given file descriptor fd is a directory or not.
(wrapper around node's native fs.stat.isDirectory() method )


Install from NPM

npm install isdir --save

In your script

var isdir = require('isdir');
var fd    = __dirname; // or what ever you need to check

isdir(fd, function callback(err, dir) { // named callback function
  if(err) { // you will get an error back if fd was not a readable file or dir
    console.log("Oopsy: " + err); // handle errors in your preferred way.
  else if(dir) {
    console.log(fd + " is a directory!"); // do something with the directory
  else {
    console.log(fd + " is NOT a directory!") // its a file


We needed a fully tested simple call to check if a descriptor is a directory for our faster project.
This module deliberately only exposes a single asynchronous method.
If you prefer to use it
sychronously (go for a walk and consider switching programming languages) and if you still want to use it sync just assign the output to varaiable and omit the callback:
var isdir = require('isdir');
var fd    = __dirname;        // or what ever descriptor you need to check
var dir   = isdir(__dirname); // this works but is not encouraged (its blocking)
if(dir) {
  // do what you want with your directory

Influenced by: (We wanted lighter error-handling and more tests)