The API doc describes the constants will return a object:
https://nodejs.org/api/fs.html#fs_fs_constants
But, in fact, fs doesn't exist constants of property.
> fs.constants
undefined
The fs shows on console as following:
> fs
{ Stats: [Function],
F_OK: 0,
R_OK: 4,
W_OK: 2,
X_OK: 1,
access: [Function],
accessSync: [Function],
exists: [Function],
existsSync: [Function],
readFile: [Function],
readFileSync: [Function],
close: [Function],
closeSync: [Function],
open: [Function],
openSync: [Function],
read: [Function],
readSync: [Function],
write: [Function],
writeSync: [Function],
rename: [Function],
renameSync: [Function],
truncate: [Function],
truncateSync: [Function],
ftruncate: [Function],
ftruncateSync: [Function],
rmdir: [Function],
rmdirSync: [Function],
fdatasync: [Function],
fdatasyncSync: [Function],
fsync: [Function],
fsyncSync: [Function],
mkdir: [Function],
mkdirSync: [Function],
readdir: [Function],
readdirSync: [Function],
fstat: [Function],
lstat: [Function],
stat: [Function],
fstatSync: [Function],
lstatSync: [Function],
statSync: [Function],
readlink: [Function],
readlinkSync: [Function],
symlink: [Function],
symlinkSync: [Function],
link: [Function],
linkSync: [Function],
unlink: [Function],
unlinkSync: [Function],
fchmod: [Function],
fchmodSync: [Function],
chmod: [Function],
chmodSync: [Function],
fchown: [Function],
fchownSync: [Function],
chown: [Function],
chownSync: [Function],
_toUnixTimestamp: [Function: toUnixTimestamp],
utimes: [Function],
utimesSync: [Function],
futimes: [Function],
futimesSync: [Function],
writeFile: [Function],
writeFileSync: [Function],
appendFile: [Function],
appendFileSync: [Function],
watch: [Function],
watchFile: [Function],
unwatchFile: [Function],
realpathSync: [Function: realpathSync],
realpath: [Function: realpath],
createReadStream: [Function],
ReadStream:
{ [Function: ReadStream]
super_:
{ [Function: Readable]
ReadableState: [Function: ReadableState],
super_: [Object],
_fromList: [Function: fromList] } },
FileReadStream:
{ [Function: ReadStream]
super_:
{ [Function: Readable]
ReadableState: [Function: ReadableState],
super_: [Object],
_fromList: [Function: fromList] } },
createWriteStream: [Function],
WriteStream:
{ [Function: WriteStream]
super_: { [Function: Writable] WritableState: [Function: WritableState], super_: [Object] } },
FileWriteStream:
{ [Function: WriteStream]
super_: { [Function: Writable] WritableState: [Function: WritableState], super_: [Object] } } }
I suggest it should mark the property has been deprecated. Otherwise, it will cause misunderstanding.
@TonyPythoneer fs.constants
is not defined in the v4.x documentation, which can be found here
Closing. Please feel free to ask any questions
edit: the docs you linked to are for v6.x
@TheAlphaNerd Thank you for your notification.
@TheAlphaNerd I just encountered the issue when I tried to access fs.constants.F_OK
I'm on node v6.1.0 and I can confirm that there isn't a fs.constants
object exported.
Simple test :
node -e "const fs = require('fs'); console.log(process.versions.node); console.log(fs.constants);"
Output :
6.1.0
undefined
EDIT : Sorry, I just realized that this change wasn't in v6.1.0. https://nodejs.org/docs/v6.1.0/api/fs.html :D
FYI:
fs.constants === undefined
fs.constants !== undefined
I use the following in my code for compatibility, e.g.
fs.accessSync(binPath, (fs.constants || fs).X_OK)
@MylesBorins Should this needs to be added to documentation also as a __Note__? Because post 6.3
fs.constants exist but not pre. And api documentation here says Added in: v0.11.15
Feel free to send a PR to master with what you think will help and we can discuss there
Why is this closed ? I just stumbled over this and https://nodejs.org/dist/latest-v6.x/docs/api/fs.html does not declare in which version fs.constants was added.
Reopening, this will be closed by https://github.com/nodejs/node/pull/12690 when it lands.
Most helpful comment
FYI:
fs.constants === undefined
fs.constants !== undefined
I use the following in my code for compatibility, e.g.