It’s been a little while since the last Node.js release, but the wait was worth it. Node.js 19 comes with some fascinating features that are sure to make your life as a developer easier and more enjoyable.
NodeJs 19 is set to replace NodeJS 18, but it won’t be promoted to long-term support (LTS) (as only even-numbered NodeJS versions are promoted to LTS, but it will remain as the current release until April 2023.
We understand that NodeJS 18 was just promoted to LTS status a few days ago, but that will not stop us from looking at the new features and improvements in Node.js 19.
Before we dig deep into all of the new goodies that Node.js 19 has in store, let’s briefly go over what LTS is and how it works with Node.js releases.
What’s Node JS?
By I/O, we mean input/output, and by non-blocking I/O, we mean Node.js can handle multiple requests simultaneously without waiting for any single request to finish before starting on the next one. That makes Node.js very efficient and fast.
Node.js is open source and cross-platform, meaning it can run on any operating system, including Windows, Linux, and macOS.
- Create, open, write, read, delete, and close files on the server
- Collect form data
- Generate dynamic page content
- Add, delete, and modify data in your database
Key Features of Node.js
Asynchronous and Event-Driven: All APIs of the Node.js library are asynchronous, that is, non-blocking. It simply means a NodeJS-based server never waits for an API to return data. After calling it, the server moves to the next API, performing other tasks. So, when the data is available, it sends a callback to the required function.
Single-Threaded but Highly Scalable: Node.js uses a single-threaded model with event looping. The event mechanism helps the server to respond in a non-blocking way and makes the server highly scalable, unlike traditional servers, which create limited threads to handle requests. Node.js uses a single-threaded program, and the same program can provide service to a much larger number of requests than traditional servers like Apache HTTP Server.
No Buffering: Node.js applications don’t have to buffer data. Instead, they output the data in chunks.
License: Node.js is released under the MIT license.
As we can see, Node.js has some impressive features that make it an excellent choice for developing scalable network applications.
A Brief History of Node.js
Dahl started working on Node.js in May 2009 and released the first version in November of that year. Since then, Node.js has been under active development, with a new release every six months.
The latest stable release is Node.js 19, released on October 18th, 2022.
The name Node.js comes from the fact that it uses a node to represent a server in the network. Dahl wanted to create a small and lightweight runtime environment that was easy to use and could be easily embedded into other applications.
How LTS Works with Node.js Releases
Node.js follows a release schedule similar to the Google Chrome web browser. There are two types of releases:
Current Stable Release: These are released every six months and receive eight-month support. The odd-numbered releases (e.g., v5, v7) are considered stable releases.
LTS Releases: These are released every six months but receive support for 30 months. The even-numbered releases (e.g., v4, v6) are considered LTS releases.
The current LTS release is Node.js 18, released on April 2021. It will be supported until October 2025. That means if you update to Node.js 18 now, you’ll get security and performance updates for the next three years.
What’s the Difference Between LTS and Current Releases?
The node version you use depends on the project you are working on.
If you are working on a project requiring long-term support, you should use an LTS release. These releases are supported for 30 months and receive regular security and performance updates.
After the first six months, and library vendors have had enough time to test and implement new features, the current release becomes an LTS release.
What Goes into a Major Node.js Release?
New Node.js versions are about speed, bug fixes, stability, and feature updates. With every new Node.js release, the team strives to make Node.js faster, more stable, and easier to use.
And since Node is built on other technologies, it’s only natural that new Node versions also include updates to those dependencies.
V8 Engine Updates
With every new Node release, Node.js has to be updated to be at par with the latest V8 engine. The engineers at Node.js work hard to ensure that Node.js is always up-to-date with the latest V8 engine.
For example, Node.js 10 added support for ECMAScript modules, a feature that allows you to modularize your code.
Key Changes In Major Node Versions
It’s clear that with every new Node.js release, there are new features and updates. But what are the key changes in each major Node version?
Node 6 Implemented ES6
Perhaps the most important change in Node.js 6 was that it implemented the then-new ECMAScript 6 script.
Node 8 Introduced Async/Await
Node 8 was a huge update that included an improved error handling API, N-API version 3, and async/await support.
Async/await is a feature that allows you to write asynchronous code that looks and reads like synchronous code.
Async and Awaits are special keywords you can use in your Node.js functions to make them wait for promises to resolve before continuing execution.
Node 10 Added Promisified Fs Modules
Node.js 10 was a significant update that included many features and improvements. The most notable feature was the addition of promisified fs modules.
Promisified fs modules are modules that return promises instead of callbacks. That makes working with the file system much easier and more convenient.
Node 12 Implemented ES6 Modules
If you’ve worked with React and Node.js, you know React uses a different module system called CommonJS.
Node.js has always used the CommonJS module system. However, with the release of Node.js 12, that changed.
Node.js 12 now supports ECMAScript modules out of the box. That means you can write your Node.js code using the same import and export syntax you use in React applications.
Can You Install Multiple NodeJS Versions?
Yes — you can install multiple Node.js versions on your system and switch between them as needed. That’s a great way to ensure your Node.js application is compatible with different Node.js versions.
You can install multiple Node.js versions using a tool like nvm (Node Version Manager).
NVM is a tool that allows you to easily install, manage, and switch between different Node.js versions.
Node 18 Is The Current LTS Release
Node.js 18 was recently promoted to LTS (Long Term Support). That means that it will be supported until 2025.
Released in April 2021, Node.js 18 is the current LTS release.
What’s New in Node.js v18?
As expected, Node.js 18 brings with it several improvements, including:
#1. Native Fetch API Support
The fetch API is a browser API that allows you to make network requests.
For example, you can use the fetch API to request an HTTP server and receive a response.
The fetch API is widely used in web applications and is very convenient.
Previous versions of Node.js didn’t support native fetch API by default. You had to use a third-party library like node-fetch.
However, Node.js 18 now supports the native fetch API.
That means you can use the fetch API directly in your Node.js applications without installing third-party libraries.
#2. Node watch
Node.js 18 introduced a new feature called Node watch.
The node watch mode allows you to restart your Node.js application when a file is changed automatically.
That’s an excellent feature for development because it means you don’t have to restart your application every time you change something.
You can use the –watch-path to specify which path to observe for changes.
Remember that the flags cannot be combined with –eval, –check, –interactive, or –print.
If you use any of these flags, the watch mode will be disabled.
And yes, you can use Node Watch Index on your file name without installing any dependencies.
#3. OpenSSL 3 Support
OpenSSL is a cryptography library that provides various cryptographic algorithms.
It’s an open-source implementation of SSL, TSL, and other network protocols.
OpenSSL is very popular, and a lot of applications use it.
However, it has some security vulnerabilities.
One of the most notable security vulnerabilities is the Heartbleed bug.
The Heartbleed bug is a security vulnerability that allows attackers to read the memory of applications that use OpenSSL.
That can lead to sensitive information such as passwords and private keys being compromised.
OpenSSL 3, the latest version of OpenSSL, addresses the Heartbleed bug.
Node.js 18 now supports OpenSSL 3.
That means that your Node.js applications will be more secure against the Heartbleed bug and other security vulnerabilities.
#4. The Experiment note: test
The Node: test module facilitates writing unit tests for your Node.js applications.
It’s similar to the popular Mocha testing framework.
TAP is a popular test reporting format used by many testing tools.
The Node: test module is only available as the Node: scheme.
And yes, it’s still in the experimental stage, not yet ready to replace complete alternatives such as Mocha or Jest.
It would be best if you only used it to try out the new features and API.
The test runner supports features like test skipping, subtests, callback tests, etc.
The following is a simple example of a test script that uses the Node: test module.
More information about the module can be found in the documentation.
#5. Prefix-only Core Modules
Node.js 18 introduces a new feature called prefix-only core modules.
Prefix-only core modules are a new way to import modules that leverage the ‘node:’ prefix, making it immediately evident that the module is coming from Node.js.
That is an excellent feature for developers because it makes it easier to understand where a module is coming from.
You don’t have to type out the full module name when importing a module from Node.js.
To learn more about this feature, we suggest you check out “Colin Ihrig’s article.
#6. Experimental Web Streams API
The Streams API is a robust API for working with streaming data.
It’s still in the experimental stage, but Node.js 18 supports it.
The Streams API is a low-level API.
If you’re looking for a higher-level API, we suggest you check out the WHATWG Fetch API or the Node: http2 module.
The following is a simple example of how to use the Streams API.
#7: Other Global APIs
Node.js 18 also introduces a few other global APIs.
The first is the URL API.
The URL API allows developers to parse and manipulate URLs.
It’s similar to the Java URL and URI class.
The second is the TextDecoder API.
The TextDecoder API allows developers to decode text from an array buffer.
The third is the TextEncoder API.
The TextEncoder API allows developers to encode text into an arrayBuffer.
The fourth is the v8: HeapSnapshot API.
The v8: HeapSnapshot API allows developers to take snapshots of the v8 heap.
That is useful for debugging memory leaks.
The fifth is the v8: Isolate API.
The v8: Isolate API allows developers to create isolates.
Isolates are separate execution contexts that allow you to run multiple instances of Node.js side-by-side.
That is useful for creating multi-tenant applications.
More information about these APIs can be found in the documentation.
#8: V8 Version 10.1
Node.js 18 ships with V8 version 10.1.
Version 10.1 of V8 includes some interesting performance improvements and new features.
New Array Methods for finding the last index of an element: Array methods such as findLastIndex and findLast are now available.
Improved Async/Await Performance: Async/await performance has been improved in V8 10.1.
The data format of the newer v8.serialize function has also been changed, and it’s not compatible with older versions of Node.js.
International Support: intl.supportedValuesOf and the intl.locale functions have been added to support internationalization.
More information about these features can be found in these V8 release notes.
#9: Toolchain and Compiler Upgrades
Node.js 18 ships with a new compiler and runtime.
The toolchains are well-evaluated and elevated.
Node.js provides pre-built binaries for all supported CPU architectures. And with every new release, the minimum toolchain requirements are assessed and updated as necessary.
- The pre-built binaries for Linux are built on RHEL 8 (Red Hat Enterprise Linux) and use Glibc 2. 28.
- The pre-built binaries for macOS are built on 10.15 High Sierra and use the macOS system provided libc.
- For AIX, the minimum supported version is 7.2.
#10: HTTP Timeouts
The Node.js HTTP module has changed significantly in Node.js 18.
- The headersTimeout: the time it takes to receive the first byte of the response headers has been increased to 60 seconds.
- The requestTimeout: the time it takes to receive the first byte of an HTTP request is set to 5 minutes (300,000 milliseconds) by default.
#11: Undici Library
The Node.js 18 release comes with a new HTTP client called Undici.
Undici is a library that provides a simple, Promise-based API for making HTTP requests.
It’s similar to the Fetch API but designed specifically for Node.js.
- Keep alive by default
- No pipelining
- LIFO scheduling
- Can follow redirected (opt-in)
- Unlimited connections
For more information, we suggest you watch this Lizz’s talk on New and exciting Features in this new version of Node.js.
Other Features and Improvements
Other features and improvements in Node.js 18 include:
- default DNS resolution
- Async Hooks
- WASI support
- Trace events
- Direct network imports: Node.js 18 now supports importing files from the network using the “import” keyword.
- JSON Import Assertions: Node.js 18 now supports the “import.meta.type” keyword to assert that the imported JSON file has a specific type.
Upgrading to Node.js V18
If you’re already using Node.js, we recommend upgrading to the latest version.
The Node.js project has a comprehensive guide to upgrading to the latest version.
If you’re using a Node.js version manager such as nvm, you can upgrade to the latest version with a single command:
nvm install v18.0.0
Alternatively, use this official link to download the latest version of Node.js for your platform and architecture:
Why Should You Migrate to Node.js 18 (Migration and Deprecation)
Here are some of the reasons to migrate to Node.js 18:
- Globally available browser APIs like Web Streams and Fetch APIs for developers
- It upgrades V8 to version 10.1, which comes with loads of new and advanced features like new array methods, promises, async functions, and much more
- The new release comes with a new HTTP client called Undici
- It also ships with a brand new compiler and runtime along with well-evaluated and elevated toolchains
- Other features include Direct network imports, support for HTTP and HTTPS imports, JSON import assertions, and more
- The Node.js 18 release also deprecated some APIs like the Buffer constructor and process.versions.electron (Use process.electron version instead).
Migration and Deprecation Guide
For Linux and Mac Users, here are the commands to migrate to the latest version of Node.js:
The module n makes it easy to install and manage different versions of Node.js:
First, install n using npm:
npm install n -g
For the latest stable version:
For the latest release:
The numerous reasons stem from Node’s performance, scalability, concurrency, and programming model benefits.
In addition, the Node community has done an excellent job of providing a rich set of tooling and libraries to support modern software development practices.
That explains why tech giants like Netflix, PayPal, LinkedIn, IBM, Microsoft, and eBay are all switching to Node.
It should be noted that Node.js 12 is no longer supported and that you should consider upgrading your applications to the latest LTS version, Node.js 18, at the time of writing this.