Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ivanfon/simple-exist
Simple functions to check if a file exists in both sync and async using Node.js.
https://github.com/ivanfon/simple-exist
Last synced: 15 days ago
JSON representation
Simple functions to check if a file exists in both sync and async using Node.js.
- Host: GitHub
- URL: https://github.com/ivanfon/simple-exist
- Owner: IvanFon
- License: gpl-3.0
- Created: 2016-03-16T23:04:00.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-09-10T00:39:35.000Z (about 6 years ago)
- Last Synced: 2024-04-24T20:13:27.551Z (7 months ago)
- Language: JavaScript
- Size: 15.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# simple-exist
Simple functions to check if a file exists both synchronously and asynchronously.## Install
Use your favourite Node.js package manager:
```
yarn add simple-exist
npm install simple-exist
```## Usage
### exists(file, callback)
Works asynchronously. Pass in a filename as a string and get either `true` or `false` as a callback argument.
#### Example
```
const exists = require('simple-exist').exists;exists('file', res => {
if (res) {
// File exists
} else {
// File does not exist
}
});
```### existsSync(file)
Works synchronously. Pass in the filename as a string. The function will return either `true` or `false`.
**Note: Node.js' `fs.existsSync` is no longer deprecated, and you should use that instead. This function has been kept in this module for backwards compatability.**
#### Example
```
const exists = require('simple-exist').existsSync;if (existsSync('file')) {
// File exists
} else {
// File does not exist
}
```## Testing
To run tests, install development dependencies (`yarn -D`, `npm i -D`) and run the `test` script (`yarn run test`, `npm run test`).