Node.js 19’s New Watch Mode and Other Features You Should Know About

In October 2022, Node.js released its 19th version. It came six months after the release of Node.js v.18, which featured significant upgrades such as the native test runner module.

A notable feature in Node.js 19 is the new and experimental watch mode. This allows you to make changes to your server without having to restart it.

4

Before Node.js 19, watch mode was only possible using third-party libraries. Learn how to use the watch mode and explore other updates to Node.js in version 19.

Node’s New Watch Mode

Node.js 19 introduces the experimental–watchflag, which restartsa Node.js serverwhen it detects changes in the specified file. You could do this previously using a third-party library callednodemon, but the update removes the need for a dependency by adding its functionality to Node.js.

To restart your Node.js server using the–watchflag, run thenodecommand with the–watchflag followed by the name of the file you want to restart when Node detects changes.

a person holding up a node.js sticker

For example, consider this code block as aserver.jsfile:

To watch this file for changes, and restart the server when they occur, run this command on your terminal:

a person holding up a node.js sticker

The command will watch your server.js file and restart the Node.js server when it detects changes made in the file.

It is worth noting that this feature is still experimental, which means you may experience issues while using the–watchflag to restart your server.

Apple’s Siri assistant on an iPhone 16 Pro

Other Upgrades and Fixes

Other improvements and fixes that came with Node.js 19 include the following.

HTTP Keep-Alive by Default

Thehttp/httpsmodule’skeepAliveoption controls whether it should keep a connection to a server after it has completed a request. Originally, you would have to set thekeepAliveoption totruemanually. This option instructs the server to keep the connection open and reuse it for subsequent requests.

In Node.js 19, thekeepAliveoption is set to true by default. This addition will significantly reduce the overhead of establishing new connections.

Several laptops side by side with different Linux distributions.

Stabilization of the WebCrypto API

The WebCrypto API is Node.js’s implementation ofthe Web Crypto API standard. With Node.js 19, the WebCrypto implementation is now stable, except for theEd25519,Ed448,X25519, andX448algorithms.

You can access this API using theglobalThismodule or thenode:prefix thatNode.js 18 introducedto differentiate core Node.js modules from third-party libraries.

For example:

Custom ESM Resolution Adjustments

Node.js 19 removes the previously experimental–experimental-specifier-resolutionflag. This provided experimental support for locating files using package specifiers, similar to how ECMAScript imports modules.

Node.js removed this flag because you can replicate their functionality using custom loaders. You can use custom loaders to support more module formats or to process modules further before loading since they let you provide your unique logic for loading and processing modules.

Removal of DTrace/SystemTap/ETW Support

DTrace, SystemTap, and ETW (Event Tracing for Windows) are modules that offer dynamic tracing and analysis of running programs. Originally in Node.js, you could use them to gather data on an application’s activity, including performance indicators, errors, and other possible runtime occurrences.

In Node.js 19, Node.js removed support for DTrace, SystemTap, and ETW because the complexity involved in maintaining and keeping these modules up-to-date has yet to be worth it. So, to prioritize their resources, they dropped support for them.

Upgrading to Node.js 19

Node.js 19 introduces various features and improvements worth considering for your application, including the new watch mode, among others discussed above. To upgrade to Node.js 19, head to the official website and download the current version.

With Node.js 17 reaching end of life, it’s time to look at what you need to change to keep using a supported version of the development environment.

When your rival has to bail out your assistant.

Don’t let aging hardware force you into buying expensive upgrades.

Now, I actually finish the books I start.

It saves me hours and keeps my sanity intact.

Unlock a world of entertainment possibilities with this clever TV hack.

Technology Explained

PC & Mobile