Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

exists-file

kikobeats20.4kMITdeprecated3.0.2

This package is a perf sacrilege. Use fs.existsSync() instead

Check if a file exists. A fs.exists implementation that is not deprecated.

directory, exists, file, file system, filesystem, fs, recursive

readme

exists-file

Last version Build Status Coverage Status Dependency status Dev Dependencies Status NPM Status Donate

Check if a file exists. A fs.exists implementation that is not deprecated.

Because fs.exist and fs.existsSync are deprecated this an implementation using fs.stats and fs.statsSync for get the same result.

Also always keep in mind:

fs.exists() should not be used to check if a file exists before calling fs.open(). Doing so introduces a race condition since other processes may change the file's state between the two calls. Instead, user code should call fs.open() directly and handle the error raised if the file is non-existent.

Install

npm install exists-file --save

Usage

var existsFile = require('exists-file')

// async with a callback
existsFile('./README.md', console.log) // => null, true

// async with a promise
existsFile('./README.md').then(console.log).catch(console.error) // => true

// sync
var exists = existsFile.sync('./README.md')
console.log(exists) // => true

API

existsFile(filepath, [cb])

filepath

Required
Type: string

The relative or absolute file path.

cb

Type: function

If cb is not provided then it returns a promise.

existsFile.sync(filepath)

filepath

Required
Type: string

The relative or absolute file path.

License

MIT © Kiko Beats

changelog

3.0.2 (2017-07-18)

  • Update README.md (d7e1869)
  • docs(readme): add Greenkeeper badge (6576293)
  • chore(package): update dependencies (83b6b32)

3.0.1 (2017-04-27)

BREAKING CHANGE

  • This module no longer supports Node.js 0.10

3.0.0 (2016-10-09)

  • Complete docs (f34d078)
  • Update README.md (55ebf9c)
  • fix: functions throw error when the path argument is not string (19f32db)
  • feat: return a promise when no callback passed (4de5802)

BREAKING CHANGE

  • it was not throwing error before

2.1.0 (2016-06-28)

  • Removed unnecessary dep (f6e6d63)

2.0.2 (2016-06-15)

2.0.1 (2016-06-15)

2.0.0 (2016-05-03)

  • Breaking changes: Refactor API (f37c2a1)

1.0.2 (2016-05-03)

1.0.1 (2016-04-17)

1.0.0 (2015-06-16)