Skip to Content
APIaccess

access

Check whether the process can access a file with the given mode (F_OK, R_OK, W_OK, X_OK). Rejects if access is denied.

Basic usage

import { access } from '@rush-fs/core' import { constants } from 'node:fs' await access('./file.txt') // F_OK default await access('./file.txt', constants.R_OK) await access('./script.sh', constants.X_OK)

Methods

access(path, mode?)

Async. Returns Promise<void> (rejects on access denied).

ArgumentTypeDescription
pathstringFile path.
modenumberOptional. F_OK, R_OK, W_OK, X_OK (from fs.constants).

accessSync(path, mode?)

Sync. Same arguments; throws on access denied.

Performance

From repo benchmarks (pnpm build && pnpm bench):

ScenarioNode.jsRush-FSSpeedup
access R_OK (directory)4.18 µs1.55 µs2.7x
ScenarioNode.jsRush-FSNote
accessSync F_OK456 ns1.46 µsNode.js fast path

Rush-FS is faster for typical access checks; for F_OK-only sync checks Node.js can be faster due to internal fast path.

Notes

  • Prefer exists: If you only need “file exists”, exists(path) is simpler; access(path, F_OK) is the lower-level API.
  • Constants: Use constants.F_OK, R_OK, W_OK, X_OK from node:fs (or the numeric values).
Last updated on