What's new in Node.js 27
本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。
Title: What’s new in Node.js 27
标题:Node.js 27 有哪些新特性
Table of Contents Quick Answer: what’s new in Node.js 27 New Iterator superpower: zip, zipKeyed, join, and includes Pairing sequences lazily with Iterator.zip() Combining endless iterators: solar generation and household consumption Turning columns into objects with Iterator.zipKeyed() Finishing pipelines with Iterator.prototype.join() and includes() More accurate sums with Math.sumPrecise() node:net/promises and async-iterable TCP servers Virtual File System (node:vfs) is now unflagged More Node.js Core upgrades: fs, Permissions, Test Runner, and HTTP Atomic temporary files with fs.mkstemp() and native fs.glob() Permission Model gets —allow-env Built-in Test Runner: stable watch mode and Jest-style mock helpers Smarter HTTP & HTTP/2 defaults Why remove the prototype from req.headers? Under the hood: V8 15.6, the 4 GB Heap Default, and OpenSSL 4.1 Heads-up: Node.js 27 breaking changes 1. req.headers has a null prototype 2. Memory limits for multi-process deployments 3. V8 serialization format and larger heap snapshots 4. V8 behavior changes that can break tests and caches 5. Deprecations, removals, and platform changes Should you use Node.js 27 today? Wrapping up Frequently Asked Questions Why did Node.js 27 start with an Alpha release in October 2026? Will Node.js 27 become an LTS release even though 27 is an odd number? What are the biggest JavaScript features in Node.js 27? How did the default memory limit change in Node.js 27? Should I run Node.js 27 in production? 目录:快速回答:Node.js 27 有什么新功能?迭代器的新超能力:zip、zipKeyed、join 和 includes;使用 Iterator.zip() 惰性配对序列;组合无限迭代器:太阳能发电与家庭用电;使用 Iterator.zipKeyed() 将列转换为对象;使用 Iterator.prototype.join() 和 includes() 完成管道操作;使用 Math.sumPrecise() 进行更精确的求和;node:net/promises 和异步可迭代 TCP 服务器;虚拟文件系统 (node:vfs) 现已取消标记;更多 Node.js 核心升级:fs、权限、测试运行器和 HTTP;使用 fs.mkstemp() 和原生 fs.glob() 实现原子临时文件;权限模型新增 —allow-env;内置测试运行器:稳定的监视模式和 Jest 风格的模拟辅助工具;更智能的 HTTP 和 HTTP/2 默认设置;为什么要从 req.headers 中移除原型?底层技术:V8 15.6、4 GB 默认堆内存和 OpenSSL 4.1;注意:Node.js 27 的重大变更;1. req.headers 具有空原型;2. 多进程部署的内存限制;3. V8 序列化格式和更大的堆快照;4. 可能破坏测试和缓存的 V8 行为变更;5. 弃用、移除和平台变更;你现在应该使用 Node.js 27 吗?总结;常见问题解答:为什么 Node.js 27 在 2026 年 10 月以 Alpha 版本开始?尽管 27 是奇数,Node.js 27 会成为 LTS 版本吗?Node.js 27 中最大的 JavaScript 特性是什么?Node.js 27 中的默认内存限制是如何变化的?我应该在生产环境中使用 Node.js 27 吗?
On October 29, 2026, the Node.js team published v27.0.0-alpha.0.0.0. If you have been using Node.js for a few years, that version string alone probably made you do a double take. Where is the usual October v27.0.0 Current release? Node.js 27 is the first release to follow the new annual schedule. Under the old schedule, October brought a major release that reached end of life six months later without entering Long Term Support (LTS). October now starts a six-month Alpha phase, ahead of the 27.0.0 Current release in April 2027 and LTS promotion in October 2027. 2026 年 10 月 29 日,Node.js 团队发布了 v27.0.0-alpha.0.0.0。如果你使用 Node.js 已经有几年了,单是这个版本号可能就会让你感到惊讶。通常在 10 月发布的 v27.0.0 Current 版本去哪了?Node.js 27 是第一个遵循新年度计划的版本。在旧的计划下,10 月份会发布一个主要版本,该版本在六个月后即达到生命周期终点,且不会进入长期支持(LTS)阶段。现在,10 月份开启了为期六个月的 Alpha 阶段,随后是 2027 年 4 月的 27.0.0 Current 版本发布,以及 2027 年 10 月的 LTS 升级。
In this first Alpha, V8 moves from 14.6 to 15.6, adding Iterator.zip(), Iterator.zipKeyed(), Iterator.prototype.join(), Iterator.prototype.includes(), and Math.sumPrecise(). There is a promises API for node:net, along with async-iterable TCP servers. The Virtual File System (node:vfs) is now unflagged, the Permission Model gains —allow-env, and HTTP and memory defaults change too. We’ll start with the JavaScript and Node.js APIs you can use in everyday code, comparing them with the older approaches. Then we’ll cover runtime changes and what to check before upgrading. 在第一个 Alpha 版本中,V8 从 14.6 升级到 15.6,增加了 Iterator.zip()、Iterator.zipKeyed()、Iterator.prototype.join()、Iterator.prototype.includes() 和 Math.sumPrecise()。node:net 现在有了 promises API,以及异步可迭代的 TCP 服务器。虚拟文件系统 (node:vfs) 现已取消标记,权限模型增加了 —allow-env,HTTP 和内存的默认设置也发生了变化。我们将从日常代码中可以使用的 JavaScript 和 Node.js API 开始,并将它们与旧方法进行比较。然后,我们将介绍运行时变更以及升级前需要检查的事项。
Quick Answer: what’s new in Node.js 27 快速回答:Node.js 27 有什么新功能?
The main additions in Node.js 27 so far: New Iterator helpers (zip, zipKeyed, join, includes) pair sequences, join their values into strings, and search them without collecting intermediate arrays. Math.sumPrecise() sums an iterable of numbers without rounding each intermediate addition. node:net/promises and async-iterable net.Server let you use async/await to set up TCP servers and sockets. Virtual File System (node:vfs) is unflagged, making in-memory file systems and —vfs-load available without —experimental-vfs. Core upgrades across fs, permissions, test runner, and http, including atomic temp files with fs.mkstemp(), —allow-env, Jest-style mock helpers, and a 65-second HTTP keepAliveTimeout. V8 15.6 and OpenSSL 4.1 update sorting and cryptography, and the default heap limit rises to 4 GB on an 8 GB machine. 到目前为止,Node.js 27 的主要新增功能包括:新的迭代器辅助工具(zip、zipKeyed、join、includes)可以对序列进行配对、将值连接成字符串,并在不收集中间数组的情况下进行搜索。Math.sumPrecise() 对数字的可迭代对象进行求和,而不会对每个中间加法进行舍入。node:net/promises 和异步可迭代的 net.Server 允许你使用 async/await 来设置 TCP 服务器和套接字。虚拟文件系统 (node:vfs) 已取消标记,使得内存文件系统和 —vfs-load 无需 —experimental-vfs 即可使用。核心升级涵盖了 fs、权限、测试运行器和 http,包括使用 fs.mkstemp() 实现原子临时文件、—allow-env、Jest 风格的模拟辅助工具以及 65 秒的 HTTP keepAliveTimeout。V8 15.6 和 OpenSSL 4.1 更新了排序和加密功能,在 8 GB 内存的机器上,默认堆限制提高到了 4 GB。
For example, we can format a list of products and total their prices: 00-quick-answer/teaser.jsconst items = [‘Keyboard’, ‘Mouse’, ‘Monitor’]const prices = [129.99, 49.99, 349.95] const lines = Iterator.zipKeyed({ item: items, price: prices }) .map(({ item, price }) => ${item} ($${price.toFixed(2)})) .join(’, ’) console.log(${lines} -> Total: $${Math.sumPrecise(prices)})// Keyboard ($129.99), Mouse ($49.99), Monitor ($349.95) -> Total: $529.93 If you want to experiment locally, check your current Node.js version before running the snippets below.
例如,我们可以格式化产品列表并计算总价:00-quick-answer/teaser.jsconst items = [‘Keyboard’, ‘Mouse’, ‘Monitor’]const prices = [129.99, 49.99, 349.95] const lines = Iterator.zipKeyed({ item: items, price: prices }) .map(({ item, price }) => ${item} ($${price.toFixed(2)})) .join(’, ’) console.log(${lines} -> Total: $${Math.sumPrecise(prices)})// Keyboard ($129.99), Mouse ($49.99), Monitor ($349.95) -> Total: $529.93 如果你想在本地进行实验,请在运行以下代码片段之前检查你当前的 Node.js 版本。
New Iterator superpower: zip, zipKeyed, join, and includes 迭代器的新超能力:zip、zipKeyed、join 和 includes
This is the part of the release I’m most excited about. I love seeing how far we can push streams, iterators, and generators. Our article on JavaScript async iterators should give you an idea of what I mean. In What’s new in Node.js 26, we used Iterator.concat() to consume multiple iterables one after another. Node.js 27, through V8 15.6, lets us consume them side by side, pairing values at the same position. 这是此版本中我最兴奋的部分。我喜欢看到我们能将流、迭代器和生成器推向多远。我们关于 JavaScript 异步迭代器的文章应该能让你明白我的意思。在 Node.js 26 的新特性中,我们使用 Iterator.concat() 来依次消费多个可迭代对象。Node.js 27 通过 V8 15.6,让我们能够并排消费它们,将相同位置的值进行配对。
Pairing sequences lazily with Iterator.zip() 使用 Iterator.zip() 惰性配对序列
Suppose you are checking a weather forecast against the temperatures recorded over the same four days. The predictions come from your model, while the actual values come from observations. To calculate each day’s error, you need to pair the values at the same position. Both sequences must cover the same days in the same order. In Node.js 26 and earlier, if both sequences were arrays, you would typically use .map() with an index lookup: 01-iterators/iterator-zip-old.js// Node.js 26 and earlierconst predicted = [18, 21, 20, 23]const actual = [19, 20, 22, 21] const errors = predicted.map((prediction, i) => actual[i] - prediction)console.log(errors) // [1, -1, 2, -2] 假设你正在对照同一四天内记录的温度来检查天气预报。预测值来自你的模型,而实际值来自观测数据。为了计算每一天的误差,你需要将相同位置的值进行配对。两个序列必须涵盖相同的天数且顺序一致。在 Node.js 26 及更早版本中,如果两个序列都是数组,你通常会使用带有索引查找的 .map():01-iterators/iterator-zip-old.js// Node.js 26 及更早版本const predicted = [18, 21, 20, 23]const actual = [19, 20, 22, 21] const errors = predicted.map((prediction, i) => actual[i] - prediction)console.log(errors) // [1, -1, 2, -2]
That works well for arrays. But what if observations come from a generator, or your model returns an iterator of predictions? Index lookups won’t work on those inputs, and converting them to arrays means loading both sequences into memory first. In Node.js 27, Iterator.zip() takes an iterable of iterables and returns a lazy iterator of pairs. We can calculate the errors with the same pipeline whether the inputs are arrays or iterators: 01-iterators/iterator-zip.jsconst predicted = [18, 21, 20, 23]const actual = [19, 20, 22, 21] const errors = Iterator.zip([predicted, actual]) .map(([prediction, observation]) => observation - prediction) .toArray() console.log(errors) // [1, -1, 2, -2] Each pair contains a prediction and its corresponding obs 这对于数组来说效果很好。但如果观测数据来自生成器,或者你的模型返回的是预测值的迭代器呢?索引查找在这些输入上将无法工作,而将它们转换为数组意味着必须先将两个序列加载到内存中。在 Node.js 27 中,Iterator.zip() 接收一个可迭代对象的集合,并返回一个惰性的配对迭代器。无论输入是数组还是迭代器,我们都可以使用相同的管道来计算误差:01-iterators/iterator-zip.jsconst predicted = [18, 21, 20, 23]const actual = [19, 20, 22, 21] const errors = Iterator.zip([predicted, actual]) .map(([prediction, observation]) => observation - prediction) .toArray() console.log(errors) // [1, -1, 2, -2] 每一对都包含一个预测值及其对应的观测值。