diff --git a/doc/api/fs.md b/doc/api/fs.md index c4e0251a7979ae..de56e0f88c0ce8 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -789,8 +789,7 @@ with an {Error} object. The following example checks if the file `/etc/passwd` can be read and written by the current process. ```mjs -import { access } from 'node:fs/promises'; -import { constants } from 'node:fs'; +import { access, constants } from 'node:fs/promises'; try { await access('/etc/passwd', constants.R_OK | constants.W_OK); @@ -892,8 +891,7 @@ error occurs after the destination file has been opened for writing, an attempt will be made to remove the destination. ```mjs -import { constants } from 'node:fs'; -import { copyFile } from 'node:fs/promises'; +import { copyFile, constants } from 'node:fs/promises'; try { await copyFile('source.txt', 'destination.txt'); diff --git a/lib/internal/fs/promises.js b/lib/internal/fs/promises.js index c3c5874453a8b6..5f29a1df98bf61 100644 --- a/lib/internal/fs/promises.js +++ b/lib/internal/fs/promises.js @@ -17,13 +17,15 @@ const { Uint8Array, } = primordials; +const { fs: constants } = internalBinding('constants'); const { F_OK, O_SYMLINK, O_WRONLY, S_IFMT, S_IFREG -} = internalBinding('constants').fs; +} = constants; + const binding = internalBinding('fs'); const { Buffer } = require('buffer'); @@ -899,6 +901,7 @@ module.exports = { appendFile, readFile, watch, + constants, }, FileHandle, diff --git a/test/parallel/test-fs-promises-exists.js b/test/parallel/test-fs-promises-exists.js index d56308257e6b17..b9bbeee1de97fd 100644 --- a/test/parallel/test-fs-promises-exists.js +++ b/test/parallel/test-fs-promises-exists.js @@ -2,5 +2,8 @@ require('../common'); const assert = require('assert'); +const fs = require('fs'); +const fsPromises = require('fs/promises'); -assert.strictEqual(require('fs/promises'), require('fs').promises); +assert.strictEqual(fsPromises, fs.promises); +assert.strictEqual(fsPromises.constants, fs.constants);