Package Exports
- is-there
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (is-there) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
is-there 
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 tofs.exists()
andfs.open()
. Just open the file and handle the error when it's not there.fs.exists()
will be deprecated. (Source, emphasis added)
Installation
$ npm i is-there
Example
// Dependencies
var IsThere = require("is-there");
// Paths to test
var paths = [
// exist
"dir"
, "dir/another"
, "dir/another/file"
, "dir/file"
, "file"
, "file.ext"
// don't exist
, "foo"
, "foo/bar"
, "foo.bar"
, "foo/bar.foo"
].map(function (c) {
return __dirname + "/contents/" + c;
});
// Sync
console.log("> Testing sync method.");
paths.forEach(function (c) {
console.log("> %s %s", c, IsThere(c) ? "exists" : "doesn't exist");
});
console.log("> Testing async method.");
function doSeq(i) {
i = i || 0;
var cPath = paths[i];
if (!cPath) { return; }
IsThere(cPath, function (exists) {
console.log("> %s %s", cPath, exists ? "exists" : "doesn't exist");
doSeq(i + 1);
});
}
doSeq();
Documentation
IsThere(path, callback)
Checks if a file or directory exists on given path.
Params
- String
path
: The path to the file or directory. - Function
callback
: The callback function called with a boolean value representing if the file or directory exists. If this parameter is not a function, the function will run the synchronously and return the value.
Return
- IsThere|Boolean The
IsThere
function if thecallback
parameter was provided, otherwise a boolean value indicating if the file/directory exists or not.
How to contribute
Have an idea? Found a bug? See how to contribute.
Where is this library used?
If you are using this library in one of your projects, add it in this list. ✨
a-csv
by jillixcecil
by Michael Burkmanengine-tools
by jillixfontify
by Youssef Kababegenerator-catena
by Damir Kusargenerator-catena-angular-meteor-material
by Damir Kusargenerator-leptir
by Damir Kusargenerator-leptir-angular-bootstrap
by Damir Kusargenerator-leptir-angular-material
by Damir Kusargit-issues
by Gabriel Petrovaygrunt-md5assets
by petersgrunt-md5symlink
by petersheroku-docker
by Hunter Loftisjisc_build
by Martin Wood-Mitrovskilow-cli
by Jeremy Rylannode-dynamo
by Louis Larrynpm-interlink
by Orlin M Bozhinovpanes
by Joel Chupayname
by Florian CHEVALLIERramda-cli
by Raine Virtareindex-cli
by Reindexsingular_sake
by Juan Castro Fernándezsourcegate
by Orlin M Bozhinovvalkyrja
by srcspiderzow
by Jeremy Rylan