Need help with path-exists?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

sindresorhus
132 Stars 17 Forks MIT License 25 Commits 1 Opened issues

Description

Check if a path exists

Services available

!
?

Need anything else?

Contributors list

# 216
exec
test-fr...
nextjs
messeng...
17 commits
# 6,551
chalk
exec
vuejs2
sketch-...
3 commits
# 444
TypeScr...
ESLint
React
html-we...
1 commit
# 5,527
TypeScr...
typescr...
iterm2
exec
1 commit
# 7,586
TypeScr...
vscode
exec
test-fr...
1 commit
# 33,325
asteris...
exec
Babel
test-fr...
1 commit

path-exists

Check if a path exists

NOTE:

fs.existsSync
has been un-deprecated in Node.js since 6.8.0. If you only need to check synchronously, this module is not needed.

Never use this before handling a file though:

In particular, checking if a file exists before opening it is an anti-pattern that leaves you vulnerable to race conditions: another process may remove the file between the calls to

fs.exists()
and
fs.open()
. Just open the file and handle the error when it's not there.

Install

$ npm install path-exists

Usage

// foo.js
import {pathExists} from 'path-exists';

console.log(await pathExists('foo.js')); //=> true

API

pathExists(path)

Returns a

Promise
of whether the path exists.

pathExistsSync(path)

Returns a

boolean
of whether the path exists.

Related

  • path-exists-cli - CLI for this module
  • path-type - Check if a path exists and whether it's a file, directory, or symlink

Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.