文件系统常量


¥FS constants

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

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

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

¥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) => {
  // ...
});