What's New in Node.js 10
Every Node.js developer is caught in the version vortex. If you stop for a while, you’ll be several versions behind. I used to work with Node v6, and now it’s already v10 - scary, isn’t it? Some say “frontend difficulty doubles every eighteen months” - I believe that. So for new things, it’s best to actively keep up. Node v10 has been released for some time, so here’s a translated article introducing its highlights.
Node.js v10 was released on April 24, 2018, and will enter Long Term Support (LTS) in October. Let’s look at some notable features in this release.
Added Error Codes
Error messages in Node have been standardized.
In the past, handling errors was a headache. Previous errors only contained string information, and if we wanted to perform operations based on specific error messages, the only way was string matching.
Because error handling required additional string matching, even the smallest updates couldn’t be added to the next major version without breaking semantic versioning. Decoupling error information allows developers to improve error messages without introducing breaking changes. To learn more, click here
N-API is No Longer Experimental
Node documentation introduces N-API as an API for building native addons. This is an API independent of the JavaScript runtime and maintained as part of Node.js. This API is application binary interface (ABI) stable across versions of Node.js. It aims to isolate addons from changes in the underlying JavaScript engine and allows modules compiled for one version to run on later versions of Node.js without recompilation.
N-API was experimentally introduced in Node 8 and is stable in version 10. Node version updates will no longer cause module breakage, and it also introduces compatibility between Node v6.x and 8.x.
Native Node HTTP/2 More Stable
Node 8 introduced the experimental HTTP/2 module, which is a significant update. HTTP/2 enhances the standard HTTP protocol.
- Multiplexing
- Single connection
- Server push
- Prioritization
- Header compression Ending the experimental phase, the native HTTP/2 module will enable Node servers to provide better web experiences.
V8 Engine v6.6 Performance Improvements
Node ships with the V8 JavaScript engine, and Node.js v10 includes the latest version. For browsers, V8 v6.6 under Chrome 66 can reduce JavaScript parse and compile time by 20-40%. Therefore, we can expect Node 10 to benefit greatly in this area, while also providing async generators and array performance.
With software, speed is crucial, and the latest Node version focuses on improving these. To learn more, click here
Better ES Module (ESM) Support
// ESM
import pkg from "./pkg"
export default { a, b: 2 }
vs.
// CJS
const pkg = require("./pkg")
module.exports = { a, b: 2 }
Although we haven’t seen full ES module support in Node 10 yet, the Node team is still working on it, and this will continue to develop.
Node previously used CommonJS (CJS), and a new module system called ECMAScript Modules (ESM). Node has been moving in this direction.
Integrating ESM into Node isn’t a simple matter because it conflicts with the current system. However, Node is committed to finding a solution. Gil Tayar wrote an article around this topic. Interested? Click here
Diagnostic Tracing Improvements
Event tracing has been added for better visibility. This new feature can be used to improve timing and performance issue analysis. The API allows users to turn events on or off and has the capability to diagnose problems on demand.
npm v6 Arrives
npm recently upgraded from v5.7 to v6.0, and Node 10 follows this update. npm improvements focus on performance, security, and stability. To learn more about v6, click here
OpenSSL Upgraded to 1.1.0
Node comes with modern cryptographic support, including the newly added ChaCha20 encryption and Poly1305 authentication. TLS 1.3 was recently finalized, and when Node 10 enters LTS in October, it will fully support this standard.
‘fs’ Functions Have Experimental Promise Support
Interacting with the file system is a primary function of many Node applications. Node 10 will add an experimental Promise version to the fs package. Previously these functions handled asynchronous operations through callbacks, but could be converted using the util.promisify function that came with Node 8. Now developers can use promises with fs without any additional steps.
Summary
The Node team continues to push new features, enabling developers to build better experiences for users. Node 10 will bring cutting-edge technology in the future, improving error handling, building native addons, and some other obvious enhancements.
Node 10 will enter LTS from October 2018 until April 2021. The Node team follows a special odd-even release cycle. While entering LTS, Node 11 will also be released in October. Odd-numbered versions mean experimental features, while even-numbered versions are LTS versions. This will also mark the deprecation of Node 4 long-term support.
Happy JavaScripting!