With the release of Node.jsNode.js is an asynchronous event-driven JavaScript runtime and is the most effective when building scalable network applications. Node.js is free of locks, so there's no chance to dead-lock any process. Version 8 (happening on 12 PM PST 30 May), we got the latest LTS (long-term support) variant with a bunch of new features and performance improvements.
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 LTSLTS 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 AsyncAsynchrony, 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
The createHooks
function registers functions to be called for different lifetime events of each async operation.
const asyncHooks = require('async_hooks')
asyncHooks.createHooks({
init,
pre,
post,
destroy
})
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
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.
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
With Node.js Version 8, the underlying V8 JavaScript engine gets updated as well.
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
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.
Read more on TurboFan and Ignition and the TurboFan Inlining Heuristics
.
Upgrade npm to 5.0.0
The new Node.js 8 release also ships with npmnpm 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, --save
is no longer necessary as all installs will be saved by default,node-gyp
now supportsnode-gyp.cmd
on Windows,- new publishes will now include both
sha512
andsha1
checksums.
Other notable changes in Node.js Version 8
Buffer
- Buffer methods now accept
Uint8Array
as input
Child Process
- Argument and kill signal validations have been improved
- Child Process methods accept Uint8Array as input
Console
- Error events emitted when using console methods are now suppressed
Domains
- Native Promise instances are now Domain aware
File System
- The utility class
fs.SyncWriteStream
has been deprecated - The deprecated
fs.read()
string interface has been removed
HTTP
- Outgoing Cookie headers are concatenated into a single string
- The
httpResponse.writeHeader()
method has been deprecated
Stream
- Stream now supports
destroy()
and_destroy()
APIs
TLS
- The
rejectUnauthorized
option now defaults totrue
URL
- 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.