Node.js 8.0.0 – New Features and Changes

Node.js 8.0.0

Node.js Team recently released 8.0.0, the next major release, which brings in a range of significant changes and additions. Here are some of the most significant changes and features-

NPM v5.0.0
NPM Inc. recently announced the release of version 5.0.0 of the npm client. The new Node.js 8 release also ships with npm 5 – the newest version of the npm CLI.

Highlights of this new npm release:

  • A new, standardized lockfile feature meant for cross-package-manager compatibility (package-lock.json), and a new format and semantics for shrinkwrap,
  • –save is no longer necessary as all installs will be saved by default,
  • node-gyp now supports node-gyp.cmd on Windows,
  • new publishes will now include both sha512 and sha1 checksums.

V8 5.8: Preparing for TurboFan & Ingnition
Node.js 8.0.0 ships with V8 5.8. The biggest change it brings to Node.js users is that it will make possible the introduction of TurboFan and Ignition in V8 5.9. Ignition is V8’s interpreter, while TurboFan is the optimizing compiler.

“The combined Ignition and TurboFan pipeline has been in development for almost 3½ years. It represents the culmination of the collective insight that the V8 team has gleaned from measuring real-world JavaScript performance and carefully considering the shortcomings of Full-codegen and Crankshaft. It is a foundation with which we will be able to continue to optimize the entirety of the JavaScript language for years to come.” – Daniel Clifford and the V8 team

The Node.js API (N-API):
The N-API is an API for building native addons. It is independent of the underlying JavaScript runtime and is maintained as part of Node.js itself. The goal of this project is to keep the Application Binary Interface (ABI) stable across different Node.js versions.

The purpose of N-API is to separate add-ons from changes in the underlying JavaScript engine so that native add-ons can run with different Node.js versions without recompilation.

Say hello to async_hooks:
The experimental async_hooks module (formerly async_wrap) has received a major upgrade in 8.0.0. This diagnostics API allows developers a means of monitoring the operation of the Node.js event loop, tracking asynchronous requests and handles through their complete lifecycle. Complete documentation for the new module is still incomplete and users should take great care when using the experimental new module.

WHATWG URL Parser is Now Stable:
WHATWG URL parser goes from experimental status to fully supported in this version, allowing people to use a URL parser that is compliant to the spec and more compatible with the browser. This new URL implementation matches the URL implementation and API available in modern web browsers like Chrome, Firefox, Edge and Safari, allowing code using URLs to be shared across environments. Read more about the URL Parser

const URL = require('url').URL;
const myUrl = new URL('/a/path', 'https://example.org/');

Buffer security improvements:
Before Node.js version 8, Buffers allocated using the new Buffer(Number) constructor did not initialize the memory space with zeros. As a result, new Buffer instances could contain sensitive information, leading to security problems.

While it was an intentional decision to boost the performance of new Buffer creation, for most of us, it was not the intended use. Because of this, starting with Node.js 8, Buffers allocated using new Buffer(Number) or Buffer(Number) will be automatically filled with zeros.

// Zero-filled Buffers
const safeBuffer1 = Buffer.alloc(10);
const safeBuffer2 = new Buffer(10);

// Uninitialized Buffer
const unsafeBuffer = Buffer.allocUnsafe(10);

Improved support for Promises:
Node.js 8.0.0 includes a new util.promisify() API that allows standard Node.js callback style APIs to be wrapped in a function that returns a Promise. An example use of util.promisify() is shown below.

const fs = require('fs');
const util = require('util');

const readfile = util.promisify(fs.readFile);

readfile('/some/file')
.then((data) => { /** ... **/ })
.catch((err) => { /** ... **/ });

Console changes:
console.log(), console.error() and other methods available through the console module in Node.js allow application output to be directed either to stdout, stderr or pipes. Previously, errors that occurred while attempting to write console output to the underlying stream would cause the Node.js application to crash. Starting with 8.0.0 such errors will be silently ignored, making use of console.log() and the other APIs safer.

Debugger changes:
The legacy command line debugger is being removed in Node.js 8. As a command line replacement, node-inspect has been integrated directly into the Node.js runtime. Additionally, the V8 Inspector debugger, which arrived previously as an experimental feature in Node.js 6, is being upgraded to a fully supported feature.

Experimental inspector JavaScript API:
A new experimental JavaScript API for the Inspector protocol has been introduced enabling developers new ways of leveraging the debug protocol to inspect running Node.js processes.

const inspector = require('inspector');

const session = new inspector.Session();
session.connect();

// Listen for inspector events
session.on('inspectorNotification', (message) => { /** ... **/ });

// Send messages to the inspector
session.post(message);

session.disconnect();

HTTP

  • Improved support for userland implemented Agents
  • Outgoing Cookie headers are concatenated into a single string
  • The httpResponse.writeHeader() method has been deprecated
  • New methods for accessing HTTP headers have been added to OutgoingMessage

Long Term Support:
And last but not the least, Node.js 8 will enter Long Term Support(LTS) in October 2017. Once in LTS, this release will be code-named – Carbon