Home

Awesome

<!-- Please do not edit this file. Edit the `blah` field in the `package.json` instead. If in doubt, open an issue. -->

is-there

is-there

Support me on Patreon Buy me a book PayPal Ask me anything Travis Version Downloads Get help on Codementor

<a href="https://www.buymeacoffee.com/H96WwChMy" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/yellow_img.png" alt="Buy Me A Coffee"></a>

Check if a file or directory exists in a given path.

Why? fs.exists already does the job!

Because fs.exists and fs.existsSync will be are deprecated and in some cases we still need them!

fs.exists() is an anachronism and exists only for historical reasons. There should almost never be a reason to use it in your own code. In particular, checking if a file exists before opening it is an anti-pattern that leaves you vulnerable to race conditions: another process may remove the file between the calls to fs.exists() and fs.open(). Just open the file and handle the error when it's not there. fs.exists() will be deprecated. <sup>(Source, emphasis added)</sup>

:cloud: Installation

# Using npm
npm install --save is-there

# Using yarn
yarn add is-there

:clipboard: Example

const IsThere = require("is-there");

// Sync
console.log(IsThere(`${__dirname}/contents/file`))
// => true
console.log(IsThere.directory(`${__dirname}/contents/dir`))

// Callback
IsThere.file(`${__dirname}/contents/not_found`, exists => {
    console.log(exists)
    // => false
})

// Promises
IsThere.promises.directory(`${__dirname}/contents/dir`).then(exists => {
    console.log(exists)
    // => true
}).catch(console.error)

:question: Get Help

There are few ways to get help:

  1. Please post questions on Stack Overflow. You can open issues with questions, as long you add a link to your Stack Overflow question.
  2. For bug reports and feature requests, open issues. :bug:
  3. For direct and quick help, you can use Codementor. :rocket:

:memo: Documentation

isThere

Checks if a file or directory exists on given path. Use without the new keyword.

Params

Return

isThere.directory(path, callback)

Checks if the path exists and it is a directory.

Params

Return

isThere.file(path, callback)

Check if the path exists and it is a file.

Params

Return

isThere.promises()

The promises interface.

It exports the following methods:

:yum: How to contribute

Have an idea? Found a bug? See how to contribute.

:sparkling_heart: Support my projects

I open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously, this takes time. You can integrate and use these projects in your applications for free! You can even change the source code and redistribute (even resell it).

However, if you get some profit from this or just want to encourage me to continue creating stuff, there are few ways you can do it:

Thanks! :heart:

:dizzy: Where is this library used?

If you are using this library in one of your projects, add it in this list. :sparkles:

:scroll: License

MIT © Ionică Bizău