Node.js 15: Unlocking New Features and Improvements
The latest major release of Node.js is here, bringing with it a slew of exciting updates, new JavaScript language features, and some breaking changes. While Node.js 15 is not a long-term support (LTS) release, its innovative features and enhancements make it an attractive option for developers looking to stay ahead of the curve.
NPM 7: A Game-Changer for Developers
One of the most significant updates in Node.js 15 is the inclusion of NPM 7, which boasts a range of new features. NPM workspaces, for instance, allow developers to create and manage multiple NPM packages in a single file system. This feature is particularly useful for those already using the Yarn package manager or Lerna.
- Other notable changes in NPM 7 include:
- Installation of peer dependencies by default
- Introduction of the npm exec command
- Support for yarn.lock files
V8 8.6: Unlocking New JavaScript Language Features
Node.js 15 bumps the version of the V8 engine to 8.6, which brings with it several new JavaScript language features. These include:
-
- Logical assignment operators:
let obj = { x: 1 };
obj.x ||= 2;
console.log(obj.x); // Output: 1
-
- A new any() function for promises:
Promise.any([
Promise.reject('Error 1'),
Promise.resolve('Success'),
Promise.reject('Error 2')
]).then((value) => {
console.log(value); // Output: Success
});
-
- A replaceAll() function for strings:
const str = 'hello hello hello';
const newStr = str.replaceAll('hello', 'goodbye');
console.log(newStr); // Output: goodbye goodbye goodbye
These features aim to reduce the amount of code developers need to write and make their code more readable.
Experimental Support for QUIC Protocol (HTTP/3)
Node.js 15 introduces experimental support for the QUIC protocol, also known as HTTP/3. This new protocol promises to reduce latency compared to TCP, with TLS encryption baked in. Developers can start taking advantage of a new set of experimental functions and objects to establish connections using the QUIC protocol.
Breaking Changes: Unhandled Rejected Promises
One of the most significant breaking changes in Node.js 15 is how unhandled rejected promises are handled. Previously, ignoring a rejected promise would result in a warning; now, it will throw an error. Developers can revert this behavior by starting Node.js with the –unhandled-rejections=warn argument.
Experimental Diagnostics Channel Module
Node.js 15.1.0 introduces a new experimental module named diagnostics_channel. This module enables a publish-subscribe pattern that allows developers to publish arbitrary data to a channel that can be consumed by other modules or applications.
Other Notable Changes
Other notable changes in Node.js 15 include:
- Introduction of N-API 7
- Removal of the deprecated node debug command
- Removal of deprecated functions in the repl module
What’s Next?
With Node.js 15, we can expect more minor and patch releases until April 2021. After that, we’ll start to see the first few iterations of Node.js 16, which will be the next LTS release. Stay tuned for more updates and improvements in the world of Node.js!