Node.js 19 Release: What’s New
Camilo Reyes
Posted on November 22, 2022
The Node.js team recently announced the release of version 19. This has the following features:
-
node --watch
(experimental) - KeepAlive by default
- Stable WebCrypto
- V8 engine updates
In this article, we will explore the major highlights of this release. We recommend downloading the latest Node.js 19 release to follow along.
To verify your version of node:
> node --version
Let's get started!
node --watch
(Experimental)
This exciting new feature adds a file watcher using the --watch
option. Running a Node.js app in watch mode automatically restarts the process when an imported file changes.
To check out this new feature, create two files: index.mjs
and import.mjs
. This feature only works with Node.js v19.0.0 and v18.11.0+.
In the import.mjs
file write:
export const message = "Hello, World";
Then, in the index.mjs
file:
import { message } from "./import.mjs";
console.log(message);
Now run:
> node --watch index.mjs
The tool should output that it is running in watch mode. Keep in mind this is an experimental feature so it could change at any time.
Update the import.mjs
file on the fly by changing the message
:
export const message = "Hello, New World";
Note the process restarts, and the new message now appears on the console. The possibilities here are endless, as you can focus more on your code without worrying about the running process.
For the remainder of this post, run the node
executable by itself. This loads a REPL we can use to check out the rest of the new features.
node
HTTP(S)/1.1 keepAlive
by Default
With this release, Node.js sets the keepAlive
header by default, and the duration is set to 5 seconds. This reuses HTTP(S) 1.1 connections, increasing throughput because the header instructs the client on how long to stay connected. The server will also automatically disconnect any idle connections when close()
is invoked.
To check out this new feature, create an HTTP server:
const http = require("http");
const requestListener = function (req, res) {
res.writeHead(200);
res.end("Hello, World!");
};
const server = http.createServer(requestListener);
server.listen(8080);
You can copy-paste this code into the REPL or type it all out. Once the server is running, run a CURL command:
> curl -i http://localhost:8080
Note the header on the response - Keep-Alive: timeout=5
. This instructs the client to reuse connections and keep them open for 5 seconds.
Stable Web Crypto API
The Web Crypto API is now stable. You can access this module via globalThis.crypto
or require('node:crypto')
.
To check out Web Crypto API, try to encrypt - then decrypt - a secret message:
const { subtle, randomBytes } = require("node:crypto");
const iv = randomBytes(16);
const key = await subtle.generatedKey(
{
name: "AES-CBC",
hash: "SHA-256",
length: 256,
},
true,
["encrypt", "decrypt"]
);
const secretMessage = "I love node!";
const encrypted = await subtle.encrypt(
{
name: "AES-CBC",
iv: iv,
},
key,
secretMessage
);
const dencrypted = await subtle.decrypt(
{
name: "AES-CBC",
iv: iv,
},
key,
encrypted
);
const dec = new TextDecoder("utf-8");
console.log(dec.decode(decrypted));
You can also use this same API to generate symmetric and asymmetric keys (public and private keys) for your specific security needs. Please note the Ed25519/Ed448/X25519/X448 algorithms are still experimental.
V8 Engine 10.7 Updates with Intl.NumberFormat
JavaScript API
The V8 engine has been upgraded to version 10.7, which is part of Chromium 107. This version includes a new JavaScript API: Intl.NumberFormat
.
This JavaScript API enables language-sensitive number formatting.
const number = 123456.789;
const china = new Intl.NumberFormat("zh-CN", {
style: "currency",
currency: "CNY",
});
console.log(china.format(number)); //¥123,456.79
const iraq = new Int.NumberFormat("ar-IQ", {
style: "currency",
currency: "IQD",
});
console.log(iraq.format(number)); //١٢٣٬٤٥٧د.ع
const us = new Int.NumberFormat("en-US", {
style: "currency",
currency: "USD",
});
console.log(us.format(number)); //$123,456.79
The Intl.NumberFormat
object has a nice long list of options to support international number formatting.
Node.js 18 Promoted to LTS
Node.js 19 will not be promoted to LTS because only even-numbered releases are promoted to LTS. For production workloads, we recommend LTS releases. However, it is still a good time to play with Node.js 19 and provide feedback to help pave the way for future releases.
As Node.js 18 is being promoted to Active LTS, it is the recommended release for production deployments. According to the release schedule, Node.js 18 reaches end-of-life in April 2025, meaning three years of long-term support and bug fixes before then.
Node.js 18 has features that make upgrading a good choice:
- Experimental fetch
- Experimental test runner
- ECMASCript improvements
- V8 upgrade to 10.1
Check out more details in our previous blog, Node.js 18 Release: What’s New.
Wrap Up: Ecosystem Implications and Node.js 19 Release Notes
Node.js 19 continues to narrow the gap between the browser and the server. This is great news for developers who wish to work on the full stack without context-switching between languages.
The experimental watch tool is also exciting because it aids developer productivity within the platform. We hope to see more of these types of improvements in the future.
Stabilizing APIs, upgrading V8, and improving performance via KeepAlive are all signs of a healthy ecosystem that promises to deliver more features in future releases.
To see the full list of changes, be sure to look at the official Node.js 19 release notes.
P.S. If you liked this post, subscribe to our JavaScript Sorcery list for a monthly deep dive into more magical JavaScript tips and tricks.
Posted on November 22, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.