文件系统


【File system】

源代码: lib/fs.js

node:fs 模块允许以类似标准 POSIX 函数的方式与文件系统进行交互。

【The node:fs module enables interacting with the file system in a way modeled on standard POSIX functions.】

要使用基于 promise 的 API:

【To use the promise-based APIs:】

import * as fs from 'node:fs/promises';const fs = require('node:fs/promises');

要使用回调和同步的 API:

【To use the callback and sync APIs:】

import * as fs from 'node:fs';const fs = require('node:fs');

所有文件系统操作都有同步、回调和基于 Promise 的形式,并且可以通过 CommonJS 语法和 ES6 模块(ESM)访问。

【All file system operations have synchronous, callback, and promise-based forms, and are accessible using both CommonJS syntax and ES6 Modules (ESM).】