文件系统常量


🌐 FS constants

以下常量由 fs.constantsfsPromises.constants 导出。

🌐 The following constants are exported by fs.constants and fsPromises.constants.

并非每个常量在每个操作系统上都可用;这对于 Windows 尤为重要,因为许多特定于 POSIX 的定义在 Windows 上不可用。对于可移植的应用,建议在使用之前检查它们是否存在。

🌐 Not every constant will be available on every operating system; this is especially important for Windows, where many of the POSIX specific definitions are not available. For portable applications it is recommended to check for their presence before use.

要使用多个常量,请使用按位或 | 运算符。

🌐 To use more than one constant, use the bitwise OR | operator.

示例:

🌐 Example:

import { open, constants } from 'node:fs';

const {
  O_RDWR,
  O_CREAT,
  O_EXCL,
} = constants;

open('/path/to/my/file', O_RDWR | O_CREAT | O_EXCL, (err, fd) => {
  // ...
});