In this post, we’ll go through the most important features and fixes of the new Node.js 8 release.
Compared to previous Node.js major releases, 8.0.0 is rather huge. Lots going on, lots to talk about. But also very stable and well tested— James M Snell (@jasnell) May 30, 2017
The codename of the new release is Carbon. Node 8 will become the current LTS means long-term support. The acronym is often used to mark Node.js release lines that will be maintained and supported for an extended period. There are two separate kinds of LTS releases: Active and Maintenance. The Active release line often gets new features and other improvements beside security patches and bug fixes, and the Maintenance only gets the latter. It... version from October 2017 and will be maintained till December 31st, 2019. This also means that Node.js Version 6 will go into maintenance mode in April 2018, and reach the end of life in April 2019.
You can grab the nightly releases from here: https://nodejs.org/download/rc/v8.0.0-rc.2/
Introducing the Async Hooks API
The Asynchrony, in software programming, refers to events that occur outside of the primary program flow and methods for dealing with them. External events such as signals or activities prompted by a program that occur at the same time as program execution without causing the program to block and wait for results are examples of this category. Asynchronous input/output is an... Hooks (previously called AsyncWrap) API allows you to get structural tracing information about the life of handle objects.
The API emits events that inform the consumer about the life of all handle objects in Node.js. It tries to solve similar challenges as the continuation-local-storage npm package, just in the core.
If you are using continuation-local-storage, there is already a drop-in replacement that uses async hooks, called cls-hooked – but currently, it is not ready for prime time, so use it with caution!
How The Async Hooks API Works in Node.js Version 8
createHooks function registers functions to be called for different lifetime events of each async operation.
const asyncHooks = require('async_hooks')
These functions will be fired based on the lifecycle event of the handler objects.
Read more on Async Hooks, or check the work-in-progress documentation.
Introducing the N-API
Read more on the N-API.
Buffer security improvements in Node 8
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.
Are you looking for help with migrating a large-scale application to a newer Node.js version? Ask our experts.
Upgrade V8 to 5.8: Preparing for TurboFan & Ingnition
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.
Currently (well, with V8 versions older than 5.6, so anything below Node.js version 8) this is how the V8 compilation pipeline looks
Photo credit: Benedikt Meurer
The biggest issue with this pipeline is that new language features must be implemented in different parts of the pipeline, adding a lot of extra development work.
This is how the simplified pipeline looks, without the FullCode Generator and the Crankshaft:
Photo credit: Benedikt Meurer
This new pipeline significantly reduces the technical debt of the V8 team, and enables a lot of improvements which were impossible previously.
Upgrade npm to 5.0.0
The new Node.js 8 release also ships with npm is a software registry that serves over 1.3 million packages. npm is used by open source developers from all around the world to share and borrow code, as well as many businesses. There are three components to npm: the website the Command Line Interface (CLI) the registry Use the website to discover and download packages, create user profiles, and... 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,
--saveis no longer necessary as all installs will be saved by default,
- new publishes will now include both
Other notable changes in Node.js Version 8
- Buffer methods now accept
- Argument and kill signal validations have been improved
- Child Process methods accept Uint8Array as input
- Error events emitted when using console methods are now suppressed
- Native Promise instances are now Domain aware
- The utility class
fs.SyncWriteStreamhas been deprecated
- The deprecated
fs.read()string interface has been removed
- Outgoing Cookie headers are concatenated into a single string
httpResponse.writeHeader()method has been deprecated
- Stream now supports
rejectUnauthorizedoption now defaults to
- The WHATWG URL implementation is now a fully-supported Node.js API
Next Up with Node.js version 8
Node.js version 8 surprises us with a lot of interesting improvements, including the Async Hooks API which is hard to grasp with the current (but ever evolving) state of it’s documentation. We’ll start playing with the new release ASAP, and get back to you with more detailed explanations of these features soon.
If you have any questions in the meantime, please put them in the comments section below.