Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

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`).