文件系统
¥File system
稳定性: 2 - 稳定的
¥Stability: 2 - Stable
源代码: 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 模块进行访问。
¥All file system operations have synchronous, callback, and promise-based forms, and are accessible using both CommonJS syntax and ES6 Modules (ESM).