Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc has mistake: The fs doesn't exist constants of property #8044

Closed
TonyPythoneer opened this issue Aug 10, 2016 · 8 comments
Closed

Doc has mistake: The fs doesn't exist constants of property #8044

TonyPythoneer opened this issue Aug 10, 2016 · 8 comments

Comments

@TonyPythoneer
Copy link

TonyPythoneer commented Aug 10, 2016

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.

@MylesBorins
Copy link
Contributor

MylesBorins commented Aug 10, 2016

@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

@TonyPythoneer
Copy link
Author

@thealphanerd Thank you for your notification.

@jgoux
Copy link

jgoux commented Aug 11, 2016

@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

@jokeyrhyme
Copy link

FYI:

  • 6.2 has fs.constants === undefined
  • 6.3 has fs.constants !== undefined

I use the following in my code for compatibility, e.g.

fs.accessSync(binPath, (fs.constants || fs).X_OK)

@anshulguleria
Copy link
Contributor

@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

@MylesBorins
Copy link
Contributor

MylesBorins commented Apr 26, 2017

Feel free to send a PR to master with what you think will help and we can discuss there

@matthiasg
Copy link

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.

@gibfahn gibfahn reopened this May 11, 2017
@gibfahn
Copy link
Member

gibfahn commented May 11, 2017

Reopening, this will be closed by #12690 when it lands.

anshulguleria added a commit to anshulguleria/node that referenced this issue May 11, 2017
* Add changelog history in `fs.access` for the changes introduced to
  `constants` in `fs` module prior to Node `<v6.3.0`.

Fixes: nodejs#8044
addaleax pushed a commit that referenced this issue Jun 12, 2017
Add changelog history in `fs.access` for the changes introduced to
`constants` in the `fs` module prior to Node v6.3.0.

PR-URL: #12690
Fixes: #8044
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants