Code examples accompanying the article What's new in Node.js 27 on nodejsdesignpatterns.com.
Each file is a self-contained, runnable demo of a single feature.
- Node.js 27 (or
v27.0.0-alpha.0.0.0+) or newer. Several examples rely on features that landed in v27 (Iterator.zip,Iterator.zipKeyed,Iterator.prototype.join,Iterator.prototype.includes,Math.sumPrecise,node:net/promises, unflaggednode:vfs,fs.mkstemp, andnode:testmock shorthand helpers). - Files ending in
-old.jsshow how the same code looked in Node.js 26 and earlier, for side-by-side comparison.
node 01-iterators/iterator-zip.jsFor the test runner example:
node --test 05-core-upgrades/test-mocks.jsTo rerun the tests when files change:
node --test --watch 05-core-upgrades/test-mocks.jsTo try the Permission Model's environment-variable filtering, quote the wildcard patterns so the shell passes them to Node.js unchanged:
SECRET_KEY=super-secret APP_PORT=3000 \
node --permission --allow-env='PUBLIC_*,APP_*' 05-core-upgrades/permissions-env.js
# { port: '3000', secret: undefined }To run the mounted VFS entry point:
node --vfs-load=04-vfs/bundle
# Hello from the VFS bundleThe HTTP headers example asserts that the old hasOwnProperty() call throws and
then checks header presence with Object.hasOwn(). It does not validate credentials.
Start the server with Node.js 27:
node 03-net-promises/net-promises.jsIn two or three other terminals, connect with netcat:
nc 127.0.0.1 8124Each client receives its connection ID (remote address and port). Type a message
and press Enter to send it to all other clients as clientId > message. The
server does not echo messages back to their sender. Press Ctrl+C in a client
terminal to disconnect, or in the server terminal to close all connections.
The server tracks active sockets in a map, reads complete lines with readline,
and removes clients when their handlers finish. The connection loop dispatches
handlers without awaiting them, so clients can stay connected concurrently.
Socket errors and rejected handler promises are handled, and the server caps
open connections at ten.
To try the wrong, sequential version, replace the dispatch and its .catch() in
the outer connection loop with await handleConnection(socket). Only the first
client gets a handler until it disconnects. The later clients never join the map
while it remains connected, so the first client's messages have no recipients.
The server iterator yields connections, not individual chat messages. The server
keeps accepting connections while the loop waits, so slow consumers can buffer
connections without bound unless you set server.maxConnections.
| Folder | Article section |
|---|---|
00-quick-answer/ |
Quick Answer: what's new in Node.js 27 |
01-iterators/ |
New Iterator superpower: zip, zipKeyed, join, and includes |
02-math-sum-precise/ |
More accurate sums with Math.sumPrecise() |
03-net-promises/ |
node:net/promises and async-iterable TCP servers |
04-vfs/ |
Virtual File System (node:vfs) is now unflagged |
05-core-upgrades/ |
More Node.js Core upgrades: fs, Permissions, Test Runner, and HTTP |