const fs = require('fs');

const dirExists = (directory) => {
  return new Promise((resolve, reject) => {
    fs.stat(directory, function(err, stats) {
      if (err) {
        if (err.code === 'ENOENT') {
          // Directory does not exist.
          resolve(false);
        } else {
          // Some other error occurred.
          reject(err);
        }
      } else {
        // Directory exists.
        resolve(true);
      }
    });
  });
};

module.exports = dirExists;

const fs = require('fs');

const dirExists = (directory) => {
  return new Promise((resolve, reject) => {
    fs.stat(directory, function(err, stats) {
      if (err) {
        if (err.errno === 34) {
          // Directory does not exist.
          resolve(false);
        } else {
          // Some other error occurred.
          reject(err);
        }
      } else {
        // Directory exists.
        resolve(true);
      }
    });
  });
};

module.exports = dirExists;

--- 
+++ 
@@ -4,7 +4,7 @@
   return new Promise((resolve, reject) => {
     fs.stat(directory, function(err, stats) {
       if (err) {
-        if (err.code === 'ENOENT') {
+        if (err.errno === 34) {
           // Directory does not exist.
           resolve(false);
         } else {
Use err.code ENOENT to check for existence
