directory-exists

2.0.1 • Public • Published

directory-exists Build Status

Check if a directory exists - synchronously or asynchronously

Install

$ npm install --save directory-exists

Usage:

directory should be a string of a relative or absolute path.

Asynchronous

With Callback:
const directoryExists = require('directory-exists');
 
directoryExists(directory, (error, result) => {
  console.log(result); // result is a boolean
});
With Promise:

If no callback function is supplied, directoryExists returns a promise.

const directoryExists = require('directory-exists');
 
directoryExists(directory).then(result => {
  console.log(result); // result is a boolean
});
Async/await:
const directoryExists = require('directory-exists');
 
(async function() {
  const result = await directoryExists(directory);
  console.log(result);  // result is a boolean
})();

Synchronous

const directoryExists = require('directory-exists');
 
directoryExists.sync(directory); // retuns a boolean

Why not use fs.exists?

Because asynchronous fs.exists is deprecated. Synchronous fs.existsSync is still fine to use, but this library does both sync and async.

License

MIT © timmydoza

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.0.1
    4,681
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 2.0.1
    4,681
  • 2.0.0
    116
  • 1.0.2
    2,149
  • 1.0.1
    9
  • 1.0.0
    1
  • 0.0.1
    1

Package Sidebar

Install

npm i directory-exists

Weekly Downloads

4,165

Version

2.0.1

License

Unlicense

Unpacked Size

8.25 kB

Total Files

6

Last publish

Collaborators

  • timmydoza