fs 文件系统
稳定性: 2 - 稳定
源代码: lib/fs.js
node:fs
模块能够以标准 POSIX 函数为模型的方式与文件系统进行交互。
要使用基于 promise 的 API:
import * as fs from 'node:fs/promises';
const fs = require('node:fs/promises');
要使用回调和同步的 API:
import * as fs from 'node:fs';
const fs = require('node:fs');
所有文件系统操作都具有同步、回调和基于 promise 的形式,并且可以使用 CommonJS 语法和 ES6 模块进行访问。
Stability: 2 - Stable
Source Code: lib/fs.js
The node:fs
module enables interacting with the file system in a
way modeled on standard POSIX functions.
To use the promise-based APIs:
import * as fs from 'node:fs/promises';
const fs = require('node:fs/promises');
To use the callback and sync APIs:
import * as fs from 'node:fs';
const fs = require('node:fs');
All file system operations have synchronous, callback, and promise-based forms, and are accessible using both CommonJS syntax and ES6 Modules (ESM).