# @humanfs/node 中文文档

规范地址：https://npmcn.com/package/%40humanfs/node/

版本：0\.17\.0
npm 元数据更新时间：2026-09-10T12:49:38.714Z
中文译文更新时间：2026-11-05T14:50:36.004Z
软件包许可：Apache-2\.0

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40humanfs/node
原文对照：https://npmcn.com/package/%40humanfs/node/?lang=original
项目主页：https://github.com/humanwhocodes/humanfs#readme
源码仓库：https://github.com/humanwhocodes/humanfs

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：37.8 kB，7 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- Node.js 要求：\>=24\.0\.0
- 运行依赖：3 个
- 首次发布：2024-01-30T00:34:36.325Z
- 最新版本发布：2026-09-10T12:49:38.339Z
- 近 30 天下载量：507006129（2026-10-07 至 2026-11-05，npm 官方下载统计）
- 已发布版本数：20（近 12 个月 2 个）

## 中文简介

人文图书馆的Node.js装订.

## 安装

```sh
npm install @humanfs/node
```

也可以使用：`pnpm add @humanfs/node`、`yarn add @humanfs/node`、`bun add @humanfs/node`

## README

# `@humanfs/node`

以 [尼古拉斯·扎卡斯](https://humanwhocodes.com/)

如果你觉得有用,请考虑支持我的工作 [捐赠](https://humanwhocodes.com/donate) 或者说 [提名我](https://stars.github.com/nominate/) 为吉他之星.

## 说明

这个 `hfs` 用于Node.js和Node.js兼容运行时间的绑定.

> \[尖叫声\] 这个项目是 **实验** 在v1.0.0之前可能会发生重大变化。 用你自己的谨慎,绝对不要生产!

## 安装

使用您最喜欢的软件包管理器安装 :

```shell
npm install @humanfs/node

# or

pnpm install @humanfs/node

# or

yarn add @humanfs/node

# or

bun install @humanfs/node
```

## 使用量

在您的工程中最简单的使用hfs方式是导入 `hfs` 对象 :

```js
import { hfs } from "@humanfs/node";
```

然后,你可以使用 API 方法:

```js
// 1. Files

// read from a text file
const text = await hfs.text("file.txt");

// read from a JSON file
const json = await hfs.json("file.json");

// read raw bytes from a text file
const arrayBuffer = await hfs.arrayBuffer("file.txt");

// write text to a file
await hfs.write("file.txt", "Hello world!");

// write bytes to a file
await hfs.write("file.txt", new TextEncoder().encode("Hello world!"));

// append text to a file
await hfs.append("file.txt", "Hello world!");

// append bytes to a file
await hfs.append("file.txt", new TextEncoder().encode("Hello world!"));

// does the file exist?
const found = await hfs.isFile("file.txt");

// how big is the file?
const size = await hfs.size("file.txt");

// when was the file modified?
const mtime = await hfs.lastModified("file.txt");

// copy a file from one location to another
await hfs.copy("file.txt", "file-copy.txt");

// move a file from one location to another
await hfs.move("file.txt", "renamed.txt");

// delete a file
await hfs.delete("file.txt");

// 2. Directories

// create a directory
await hfs.createDirectory("dir");

// create a directory recursively
await hfs.createDirectory("dir/subdir");

// does the directory exist?
const dirFound = await hfs.isDirectory("dir");

// copy the entire directory
hfs.copyAll("from-dir", "to-dir");

// move the entire directory
hfs.moveAll("from-dir", "to-dir");

// delete a directory
await hfs.delete("dir");

// delete a non-empty directory
await hfs.deleteAll("dir");
```

如果你想创建自己的实例,请导入 `NodeHfs` 构造器 :

```js
import { NodeHfs } from "@humanfs/node";
import fsp from "fs/promises";

const hfs = new NodeHfs();

// optionally specify the fs/promises object to use
const hfs = new NodeHfs({ fsp });
```

如果你想要使用简单的胶片,导入 `NodeHfsImpl` 构造器 :

```js
import { NodeHfsImpl } from "@humanfs/node";
import fsp from "fs/promises";

const hfs = new NodeHfsImpl();

// optionally specify the fs/promises object to use
const hfs = new NodeHfsImpl({ fsp });
```

## 处理错误

-   `ENOENT` - 在大多数情况下,这些错误是默默处理的.
-   `ENFILE` 财务报告和审定财务报表 `EMFILE` - 导致这些错误的电话要经过长达60秒的重审,然后才能放弃.

## 许可证

Apache 2.0 (英语)

## 常见问题

### @humanfs/node 是什么？

人文图书馆的Node\.js装订\.

### 如何安装 @humanfs/node？

在项目目录运行 npm install @humanfs/node，或使用 pnpm add / yarn add / bun add。

### @humanfs/node 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @humanfs/node 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @humanfs/node 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=24\.0\.0。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @humanfs/node 可以商用吗？

@humanfs/node 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

### @humanfs/node 的下载量有多少？

根据 npm 官方下载统计，@humanfs/node 在 2026/10/07 – 2026/11/05 这 30 天内被下载 507,006,129 次，日均约 16,900,204 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @humanfs/node 还在维护吗？

最新版本 0\.17\.0 发布于 2026/09/10（1 个月前）；至今共发布 20 个版本，其中过去 12 个月发布了 2 个；首次发布于 2024/01/30。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

