Skip to content

Replacements for path-exists

Node.js (async)

Use fs/promises.access and return a boolean.

ts
import pathExists from 'path-exists'
import { access } from 'node:fs/promises'

const exists = await pathExists('/etc/passwd') 
const exists = await access('/etc/passwd').then(() => true, () => false) 

Node.js (sync)

Added in v0.1.21: synchronous path/file existence check via fs.existsSync.

ts
import pathExists from 'path-exists'
import { existsSync } from 'node:fs'

if (await pathExists('/etc/passwd')) 
if (existsSync('/etc/passwd')) 
  console.log('The path exists.')

Bun

Bun.file() returns a BunFile with an .exists() method.

ts
import pathExists from 'path-exists'

const path = '/path/to/package.json'
const exists = await pathExists(path); 
const file = Bun.file(path) 
const exists = await file.exists() // boolean

Released under the MIT License. (4f884625)