Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
doc: update file namespace from "package.json" to "file" variable in …
…js examples for fs.access()
  • Loading branch information
BeniCheni committed May 2, 2018
commit 59ad1f8e3930eeb2b2612db8c480de8629bb6ab1
8 changes: 4 additions & 4 deletions doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -767,22 +767,22 @@ argument will be an `Error` object. The following examples check if
const file = 'package.json';

// Check if the file exists in the current directory.
fs.access('./package.json', fs.constants.F_OK, (err) => {
fs.access(file, fs.constants.F_OK, (err) => {
console.log(`${file} ${err ? 'does not exist' : 'exists'}`);
});

// Check if the file is readable.
fs.access('./package.json', fs.constants.R_OK, (err) => {
fs.access(file, fs.constants.R_OK, (err) => {
console.log(`${file} ${err ? 'is not readable' : 'is readable'}`);
});

// Check if the file is writable.
fs.access('./package.json', fs.constants.W_OK, (err) => {
fs.access(file, fs.constants.W_OK, (err) => {
console.log(`${file} ${err ? 'is not writable' : 'is writable'}`);
});

// Check if the file exists in the current directory, and if it is writable.
fs.access('./package.json', fs.constants.F_OK | fs.constants.W_OK, (err) => {
fs.access(file, fs.constants.F_OK | fs.constants.W_OK, (err) => {
if (err) {
console.error(
`${file} ${err.code === 'ENOENT' ? 'does not exist' : 'is read-only'}`);
Expand Down