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;

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;

Use err.code ENOENT to check for existence
Use err.code ENOENT to check for existence
