Node.js v18.12.1 documentation


Table of contents

File system文件系统#

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.node:fs模块支持以标准POSIX函数为模型的方式与文件系统交互。

To use the promise-based APIs:要使用基于承诺的API:

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

To use the callback and sync APIs:要使用回调和同步API:

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).所有文件系统操作都具有同步、回调和基于承诺的表单,并且可以使用CommonJS语法和ES6模块(ESM)进行访问。