What’s New in Node 12

An overview of the Node.js 12 features and updates for the JavaScript runtime

Node.js continues its yearly release cycle with version 12 (codenamed Erbium ). Since this is as even-numbered version, it will go into Long Term Support (LTS) beginning on October 2019 and reach its end of life in April 2022.

In contrast, the odd-numbered releases are non-LTS and exist for 6–8 months between LTS releases. These are used to prepare for the next LTS release.

Node 12 is packed with great features and notable upgrades to the runtime. In addition, since Node uses the V8 engine maintained by Google and used in Chrome, Node will receive all updates from that as well.

Node 12 Features

import / export statements supported (no bundler required)

Node 12 enters Phase 3 for ECMAScript Modules which correspond to a path to stability of the modules inside Node. Initially, it will still be behind the --experimental-modules flag, and the plan is to remove the flag by the time Node 12 goes into LTS in October.

The import / export syntax has become the preferred module syntax for JavaScript developers since its standardization in ES6, and the Node team has been working diligently to enable it natively. Experimental support began in Node 8.0 at phase 0 and is taking a major step with the newest Node release. All major browsers support ECMAScript modules via <script type="module"> , so this is a huge update for Node.

Phase 3 will support 3 types of import from ES modules files (works with all built-in Node packages):

// default exports

import module from 'module' // named exports

import { namedExport } from 'module' // namespace exports

import * as module from 'module'

If you import from a CommonJS package, you can only import using default export syntax import module from 'cjs-library' .

You can use dynamic import() expressions to load files at runtime. The import() syntax returns a Promise and works with both ES Modules and CommonJS libraries.

V8 Engine

Node 12 will initially run on V8 7.4 and eventually upgrade to 7.6 during its lifetime. The V8 team has agreed to provide ABI (Application Binary Interface) stability for this range. Notable improvements with V8 7.4 are performance updates for faster JavaScript execution, better memory management, and broadened ECMAScript syntax support.

Async stack traces

Faster parsing of JavaScript

Faster calls with arguments mismatch

Faster await

Private Class Fields

Node 12 will ship with private class fields (enabled by V8). Private class field variables are only accessible within the class itself and not exposed externally. A private class field is declared by prepending a variable with the # symbol.

class Greet {

#name = 'World'; get name() {

return this.#name;

} set name(name) {

this.#name = name;

} sayHello() {

console.log(`Hello, ${this.#name}`);

}

}

In the above example, if you try to access #name outside of the class, you will receive a syntax error.

const greet = new Greet()

greet.#name = 'NewName';

// -> SyntaxError

console.log(greet.#name)

// -> SyntaxError

Improved Startup Performance

Node 12 will build a code cache for built-in libraries before build time and embed it as a binary. The main thread is able to use this code cache improving the startup time by 30%.

TLS and Security

Node now supports TLS 1.3 which offers increased security and reduced latency. TLS 1.3 has been a huge update to the protocol and is actively being integrated across the web. By implementing TLS 1.3, Node apps will have increased end-user privacy while also improving the performance of requests by reducing the time required for the HTTPS handshake. In addition, TLS 1.0 and 1.1 have been disabled by default, and the crypto library has removed deprecated functions.

Heap Size Improvements

Previously the default V8 heap sizes were used which corresponded to 700MB (32-bit systems) or 1400MB (64-bit systems). Node will now determine the heap sizes based on the available memory which will ensure it does not use more than the resources allowed.

Heap Dump Functionality

Node 12 provides the ability to generate a heap dump making it easier to investigate memory issues.

Experimental Diagnostic Reports

Node offers improved ability to diagnose issues (performance, CPU usage, memory, crashes, etc) within applications by providing an experimental diagnostic report feature.

Native Modules N-API Improvements

N-API was released to provide a more stable and native Node module system that would prevent libraries from breaking on every release by providing an ABI-stable abstraction over native JavaScript APIs. Node 12 offers improved support for N-API in combination with worker threads.

Other Notable Improvements

Worker Threads no longer require a flag

http has updated its default parser to be llhttp

has updated its default parser to be llhttp assert validates required arguments and adjusts loose assertions

validates required arguments and adjusts loose assertions buffer improvements to make it more stable and secure

improvements to make it more stable and secure async_hooks removes deprecated functionality

removes deprecated functionality Make global.process , global.Buffer getters to improve process

, getters to improve A new welcome message for repl

Conclusion

The Node team works very hard to provide yearly updates with huge improvements to Node and the overall JS ecosystem, and version 12 does not disappoint. The full CHANGELOG can be found on GitHub and additional details on the official release article.

2019 has already been a big year for Node with the Node.js Foundation merging with the JS Foundation to form the OpenJS Foundation. We continue the exciting year for JavaScript with the release of Node version 12.