fs 文件系统


node:fs 模块能够以标准 POSIX 函数为模型的方式与文件系统进行交互。

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).