npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

n8n-nodes-variable-storage

v2.4.0

Published

Execution-scoped variables for n8n workflows, with batch operations and typed values

Readme

n8n Variable Storage

在单次 n8n 工作流执行中批量设置和获取变量,支持 String、Number、Boolean、Array、Object。

安装与兼容性

在自托管 n8n 的 Settings → Community Nodes 中安装 n8n-nodes-variable-storage。 更新已经安装的包后,重启 n8n;queue 模式下所有 worker 也需要安装相同版本并重启。

开发基线是 n8n 2.22.6(n8n-core 2.22.4、n8n-workflow 2.22.3),运行它需要 Node.js >=22.16。 具体测试环境和边界见 验证报告。未经验证的旧版 n8n 不在本版本支持范围内。 从 npm 安装的非认证社区节点需要自托管 n8n;npm 发布不代表已获得 n8n 社区认证。

从 2.3.1 升级

npm 包版本与节点版本是两个不同的概念。 本次包版本为 2.4.0,新节点默认使用节点版本 2。

  • 已保存的节点 typeVersion: 1 继续使用原实现,更新包不会自动改变其行为。
  • 原版本 1 按工作流 ID 使用进程内共享变量,仍有跨执行残留、并发覆盖、重启丢失的问题。
  • 新版本 2 使用 n8n 的执行上下文;同一执行中的版本 2 节点共享变量,不同执行互相隔离。
  • 版本 1 和版本 2 不共享变量。迁移时要同时替换同一工作流中的所有 Set/Get 节点。

建议先复制工作流,再添加新版 Variable Storage 节点并复制参数、表达式和连接。 保留原节点名称,避免破坏其他节点按名称引用的表达式;检查新节点 typeVersion 为 2 后,再验证并发布工作流。 导出并编辑工作流 JSON 时,也可以统一把本包节点的 typeVersion 从 1 改成 2,再重新导入测试。 如果现有流程依赖跨执行读写变量,请改用 Data Tables、数据库或 Redis。

使用方式

Set Variables

在 Values to Set 中逐项添加 Name、Type、Value。Value 可以是固定值或 n8n 表达式。

| 类型 | 接受的值 | 示例 | | ------- | ---------------------------------------- | ------------------------------------- | | String | 字符串,或可转为字符串的数字/布尔值 | hello、={{ $json.name }} | | Number | 有限数字或非空数字字符串 | 42、3.14、={{ $json.count }} | | Boolean | 原生布尔值、0/1,或字符串 true/false/0/1 | false、={{ $json.enabled }} | | Array | JSON 数组字符串或表达式返回的原生数组 | [1,2]、={{ $json.tags }} | | Object | JSON 对象字符串或表达式返回的普通对象 | {"count":1}、={{ $json.profile }} |

版本 2 拒绝空变量名、空数字、NaN、Infinity、循环引用,以及不合法的 JSON 数据。 Boolean 字符串不区分大小写,会去除两端空格;其他文本如 yes 会报错。 一次输入 item 的所有赋值通过验证后才写入;失败 item 不留下部分赋值。

Get Variables

在 Variables to Get 中添加要读取的变量名,输出为同名 JSON 字段。 变量不存在时,可通过 Default Value 设置默认文本;留空表示未设置默认值,会报错。 默认值为字符串,例如 0 输出为 "0"。已存储的 false、0 和空字符串不会被默认值覆盖。

Manual Trigger → Variable Storage (Set Variables)
               → HTTP Request
               → Variable Storage (Get Variables)

后续节点可以通过 ={{ $json.count }} 使用 Get 节点输出的字段。 这些变量不属于 n8n 的 $vars,也不会自动注入其他节点的表达式。

可直接导入 示例工作流,测试五种类型的设置和读取。

输入字段和二进制数据

Set/Get 都支持 Include Other Input Fields:

  • All:保留所有输入 JSON 字段。
  • Selected:保留逗号分隔列表中的字段。
  • All Except:排除逗号分隔列表中的字段。

字段名按完整的顶层名称匹配,user.name 不表示嵌套路径。 变量输出覆盖同名输入字段。开启保留输入字段时也保留二进制数据引用,关闭时仅输出变量。 每个输出 item 保留与对应输入 item 的关联。

变量生命周期

版本 2 的变量保存在当前执行的 getContext('flow') 中,由 n8n 管理其生命周期:

  • 同一次执行中的节点和循环可以读写,后写入的值覆盖先写入的值。
  • 多个输入 item 共用这份变量;Set 节点执行完后,变量保存最后一个成功写入的 item 的值。
  • 独立执行和子工作流执行不共享变量。并发分支之间仍需保证 Set 在 Get 之前执行。
  • Wait 等待状态保存时,变量随执行数据保存;n8n 正常恢复这份数据时可以继续读取。
  • 这不保证任意时刻崩溃后恢复:尚未保存的运行数据仍可能丢失。
  • 单独执行 Get、跳过 Set,或只固定 Set 的输出,都不会自动创建变量。
  • 数组和对象按值保存/读取;后续节点修改输出不会反向修改存储的变量。

queue 模式的每次执行仍独立,正常保存的等待执行数据可恢复到其他 worker。 本项目不提供跨工作流、跨执行或独立于 n8n 执行数据的持久化存储。

本地开发

npm ci
npm run typecheck
npm test
npm run format:check
npm pack --pack-destination artifacts
npm run verify:pack

测试使用真实的 n8n 执行上下文与执行引擎,设置目录位于独立临时目录,不连接生产 n8n。 src/legacy/VariableNodeV1.js 是 npm 2.3.1 发布产物保留的实现;新版逻辑位于 src/VariableNodeV2.ts 和 src/storage.ts。

在 npm 发布前,可把生成的 .tgz 安装到测试用 n8n 的社区节点目录:

npm install "E:\script\n8n\N8N Variable Storage Node\artifacts\n8n-nodes-variable-storage-2.4.0.tgz"

通常该目录为 ~/.n8n/nodes;自定义 N8N_USER_FOLDER 时以实际配置为准。安装后重启测试实例。

License

MIT。包页面:npm。