Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including @alexbinary/file-exists with all npm packages installed. Try it out:

var fileExists = require("@alexbinary/file-exists")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@alexbinary/file-exists v1.0.2

Simple and consistent way to check if a file exists 🔎

file-exists

Simple and consistent way to check if a file exists 🔎

npm GitHub release Build Status dependencies Status devDependencies Status

Uses @alexbinary/promisify by alexbinary

Install

Install using npm or yarn :

$ npm install @alexbinary/file-exists
# or
$ yarn add @alexbinary/file-exists

Usage

let fileexists = require('@alexbinary/file-exists')

// callback
fileexists('/path/to/file', (err, exists) => {
  console.log('file exists: ' + (exists ? 'yes' : 'no'))
})

// promise
fileexists('/path/to/file').then((exists) => {
  console.log('file exists: ' + (exists ? 'yes' : 'no'))
})

// sync
let exists = fileexists.sync('/path/to/file')
console.log('file exists: ' + (exists ? 'yes' : 'no'))

Documentation

let fileexists = require('@alexbinary/file-exists')

fileexists(filepath)

Checks if a file exists at filepath.

This method supports both Promise and node callback style, and resolves with a boolean true if the file exists, false otherwise.

fileexists.sync(filepath)

Synchronous version. Return boolean true if the file exists, false otherwise.

License

MIT

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free