directory-exists
Version:
Check to see if a directory exists
62 lines (41 loc) • 1.47 kB
Markdown
if a directory exists - synchronously or asynchronously
```
$ npm install --save directory-exists
```
`directory` should be a string of a relative or absolute path.
```js
const directoryExists = require('directory-exists');
directoryExists(directory, (error, result) => {
console.log(result); // result is a boolean
});
```
If no callback function is supplied, directoryExists returns a promise.
```js
const directoryExists = require('directory-exists');
directoryExists(directory).then(result => {
console.log(result); // result is a boolean
});
```
```js
const directoryExists = require('directory-exists');
(async function() {
const result = await directoryExists(directory);
console.log(result); // result is a boolean
})();
```
```js
const directoryExists = require('directory-exists');
directoryExists.sync(directory); // retuns a boolean
```
Because asynchronous `fs.exists` is [deprecated](https://nodejs.org/api/fs.html#fs_fs_exists_path_callback). Synchronous `fs.existsSync` is still [fine](https://nodejs.org/api/fs.html#fs_fs_existssync_path) to use, but this library does both sync and async.
MIT © timmydoza
> Check