Skip to content

Commit 9b76453

Browse files
F3n67udanielleadams
authored andcommitted
fs: export constants from fs/promises
PR-URL: #43177 Reviewed-By: LiviaMedeiros <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent b864460 commit 9b76453

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

doc/api/fs.md

+12-5
Original file line numberDiff line numberDiff line change
@@ -789,8 +789,7 @@ with an {Error} object. The following example checks if the file
789789
`/etc/passwd` can be read and written by the current process.
790790
791791
```mjs
792-
import { access } from 'node:fs/promises';
793-
import { constants } from 'node:fs';
792+
import { access, constants } from 'node:fs/promises';
794793

795794
try {
796795
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
892891
will be made to remove the destination.
893892
894893
```mjs
895-
import { constants } from 'node:fs';
896-
import { copyFile } from 'node:fs/promises';
894+
import { copyFile, constants } from 'node:fs/promises';
897895

898896
try {
899897
await copyFile('source.txt', 'destination.txt');
@@ -1622,6 +1620,14 @@ try {
16221620
Aborting an ongoing request does not abort individual operating
16231621
system requests but rather the internal buffering `fs.writeFile` performs.
16241622
1623+
### `fsPromises.constants`
1624+
1625+
* {Object}
1626+
1627+
Returns an object containing commonly used constants for file system
1628+
operations. The object is the same as `fs.constants`. See [FS constants][]
1629+
for more details.
1630+
16251631
## Callback API
16261632
16271633
The callback APIs perform all operations asynchronously, without blocking the
@@ -6879,7 +6885,7 @@ operations.
68796885

68806886
#### FS constants
68816887

6882-
The following constants are exported by `fs.constants`.
6888+
The following constants are exported by `fs.constants` and `fsPromises.constants`.
68836889

68846890
Not every constant will be available on every operating system;
68856891
this is especially important for Windows, where many of the POSIX specific
@@ -7584,6 +7590,7 @@ the file contents.
75847590
75857591
[#25741]: https://github.com/nodejs/node/issues/25741
75867592
[Common System Errors]: errors.md#common-system-errors
7593+
[FS constants]: #fs-constants
75877594
[File access constants]: #file-access-constants
75887595
[MDN-Date]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
75897596
[MDN-Number]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type

lib/internal/fs/promises.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ const {
1717
Uint8Array,
1818
} = primordials;
1919

20+
const { fs: constants } = internalBinding('constants');
2021
const {
2122
F_OK,
2223
O_SYMLINK,
2324
O_WRONLY,
2425
S_IFMT,
2526
S_IFREG
26-
} = internalBinding('constants').fs;
27+
} = constants;
28+
2729
const binding = internalBinding('fs');
2830
const { Buffer } = require('buffer');
2931

@@ -899,6 +901,7 @@ module.exports = {
899901
appendFile,
900902
readFile,
901903
watch,
904+
constants,
902905
},
903906

904907
FileHandle,

test/parallel/test-fs-promises-exists.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22

33
require('../common');
44
const assert = require('assert');
5+
const fs = require('fs');
6+
const fsPromises = require('fs/promises');
57

6-
assert.strictEqual(require('fs/promises'), require('fs').promises);
8+
assert.strictEqual(fsPromises, fs.promises);
9+
assert.strictEqual(fsPromises.constants, fs.constants);

0 commit comments

Comments
 (0)