Skip to content

Latest commit

 

History

History
31 lines (19 loc) · 689 Bytes

path-exists.md

File metadata and controls

31 lines (19 loc) · 689 Bytes

path-exists

path-exists is a simple utility that can be replaced with platform-provided APIs.

Alternatives

Node.js

Added in v0.1.21, fs.existsSync can be used to check if a path exists. It is synchronous and returns a boolean.

import { existsSync } from 'node:fs';

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

documentation

Bun

The Bun.file() function accepts a path and returns a BunFile instance.

const path = "/path/to/package.json";
const file = Bun.file(path);

await file.exists(); // boolean;

documentation