It’s been just over six months since I published the first edition of ‘What’s new in Node.js core?’. A lot of new features have shipped in Node.js Core since then, so it felt like a good time to put together a new edition.
You can find all the code examples in this edition on GitHub (I’ll be continuing to add examples there, so you might want to give it a "watch").
The pace at which new features are being implemented and shipped is really quite impressive. A massive thank you to all the Node.js contributors for their huge efforts in pushing the Node.js project forward.
🌟 New features
Deep clone values with structuredClone()
We no longer need to use hacks to deep clone objects in Node.js.
Automatically cancel async operations with AbortSignal.timeout()
In Node.js you can now automatically cancel async operations, such as a slow HTTP request.
The Fetch API in Node.js
Making HTTP requests in Node.js just got easier with an experimental Fetch API implementation.
Import JSON in ES modules
Node.js now supports importing JSON files in ES modules without the need to pass an experimental flag.
Provide context with abortSignal.reason
It’s now possible to provide a reason value when triggering an abort signal in Node.js.
Avoid boilerplate code when handling abort signals
The abortSignal.throwIfAborted()
method makes it easier to write code that handles abort signals.
Take advantage of promise-based APIs in Node.js
There’s another pretty new promise-based API in Node.js core: the readline/promises
API.
🎞️ Video walkthrough
I’ll be recording a video walkthrough of code examples using these new features. Drop your email address in below if you’d like to watch the preview when it’s ready.
[convertkit form=3137484]
I won’t send you spam. Unsubscribe at any time.
💎 Other notable features
Here are some other notable features that have landed in Node.js core recently:
- Test module (experimental) — "A new test module that exposes an API for creating JavaScript tests". Scheduled for the v18.0.0 release on April 19th 2022.
- Error cause — Allows you to chain errors and retain contextual information (feature explainer on the V8 blog). Added v16.9.0.
- Improved support for the node: protocol — Using the
node:
protocol withrequire()
was backported in v14.18.0. - Corepack (experimental) — Makes it easier to use Yarn or pnpm as the package manager on your Node.js projects. Added v16.9.0.
- Node.js version now printed after stack trace on fatal exceptions that cause exit — Added in v17.0.0.
- url.urlToHttpOptions() — Converts a WHATWG URL object into an object that can be passed to
http.request()
orhttps.request()
. Added in v15.7.0, backported to v14.18.0. - HTTPS and HTTP imports (experimental) — "Importing network based modules using https: and http: is supported under the
--experimental-network-imports
flag". Added v17.6.0. - Scheduler API (experimental) — "An experimental API defined by the Scheduling APIs draft specification being developed as a standard Web Platform API". Added v17.3.0, backported to v16.14.0.
- Web Streams API (experimental) — "An implementation of the WHATWG Streams Standard". Added v16.5.0.
📅 Node.js releases
There are a few things to highlight about the Current and Long Term Support (LTS) Node.js release lines:
- v12 is end-of-life (EOL) at the end of April — The v12 release line enters end-of-life status on April 30th 2022. It will no longer receive critical bug fixes or security patches.
- v16 is the Active LTS release line — Since October 26th 2021 (v16.13.0). In production you should ideally be using a v16 or v14 release. v14 is in Maintenance LTS until April 30th 2023.
- v18 release coming soon — This will include all the features that have been baking in the v17 (Current) release line. Initial release scheduled for April 19th 2022, see the Version 18.0.0 release issue on GitHub for what will be included. Will enter Active LTS on October 25th 2022.
If you want to learn more about how the Node.js release schedule works, check out the Long Term Support (LTS) schedule page on the Node.js website.
Fun fact: Once v12 is EOL, top-level await is in all supported versions of Node.js (shared by Myles Borins on Twitter). Nice!