https://github.com/scottcorgan/file-exists
Check if filepath exists and is a file
https://github.com/scottcorgan/file-exists
file-exists filepath fs javascript
Last synced: about 1 year ago
JSON representation
Check if filepath exists and is a file
- Host: GitHub
- URL: https://github.com/scottcorgan/file-exists
- Owner: scottcorgan
- License: mit
- Created: 2014-07-17T23:22:20.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2022-04-28T19:35:38.000Z (about 4 years ago)
- Last Synced: 2025-03-21T01:11:12.646Z (about 1 year ago)
- Topics: file-exists, filepath, fs, javascript
- Language: JavaScript
- Size: 37.1 KB
- Stars: 33
- Watchers: 4
- Forks: 8
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# file-exists
Check if filepath exists and is a file. Returns false for directories.
_(Requires node >=6.0.0)_
## Install
```
npm install file-exists --save
```
## Usage
```js
const fileExists = require('file-exists');
fileExists('/index.html', (err, exists) => console.log(exists)) // OUTPUTS: true or false
fileExists('/index.html').then(exists => {
console.log(exists) // OUTPUTS: true or false
})
const exists = await fileExists('/index.html')
console.log(fileExists.sync('/index.html')) // OUTPUTS: true or false
```
### Options
#### fileExists(filepath[, options, callback])
* `filepath` - the path to the file to check if it exists
* `options` - an object of options
* `root` - the root directory to look in (or cwd)
* `callback(err, exists)` - gets called when checking is done
#### fileExists.sync(filepath[, options])
* `filepath` - the path to the file to check if it exists
* `options` - an object of options
* `root` - the root directory to look in (or cwd)
## Run Tests
```
npm install
npm test
```