@humanfs/node

中文文档
0.17.0发布于 2026/09/10Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 5.1亿

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

中文使用文档
文档目录5 节
  1. 说明
  2. 安装
  3. 使用量
  4. 处理错误
  5. 许可证

@humanfs/node

以 尼古拉斯·扎卡斯

如果你觉得有用,请考虑支持我的工作 捐赠 或者说 提名我 为吉他之星.

说明

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

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

安装

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

npm install @humanfs/node

# or

pnpm install @humanfs/node

# or

yarn add @humanfs/node

# or

bun install @humanfs/node

使用量

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

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

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

// 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 构造器 :

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 构造器 :

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 共发布 20 个版本,首次发布于 2024/01/30;过去 12 个月发布了 2 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.17.0latest2026/09/101 个月前
0.16.82026/04/186 个月前
0.16.72025/09/031.2 年前
0.16.62024/10/282 年前
0.16.52024/09/102 年前
0.16.42024/07/242 年前

关于 @humanfs/node 的常见问题

@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 和提交记录判断。