What are the important features and fixes in Node.js 8?

At 12:00 on May 30th, Node.js 8 was officially released, this version has a series of new features and performance improvements, and these features and improvements will receive long-term support (LTS).

 

Here's a look at the most important features and fixes in Node.js 8 release.

 

The codename for the new version is Carbon. Node.js 8 will officially become the current LTS release from October 2017 and will continue until December 31, 2019. This also means that Node.js version 6 will enter maintenance mode in April 2018 and end maintenance support in April 2019.

 

Download Node.js 8 version: https://nodejs.org/download/rc/v8.0.0-rc.2/

 

Async Hooks API Introduction

The Async Hooks (formerly AsyncWrap) API allows obtaining structural tracking information about the lifecycle of a handle object.

 

Messages from the API inform the consumer of the lifecycle of all handle objects in Node.js. It tries to solve a problem similar to the continuation-local-storage npm package .

 

If you're using continuation-local-storage, you can already use async hooks called cls-hook instead - it's just not the best time to use async hooks, so use with caution!

 

How the Async Hooks API works in Node.js 8

The registration function of the createHooks function is called by different lifecycle events for each asynchronous operation.

const asyncHooks = require('async_hooks')
asyncHooks.createHooks({  
  init,
  pre,
  post,
  destroy
})

Learn more about Async Hooks , or check out the work-in-progress documentation . These functions will be selectively triggered based on lifecycle events of the handler object.

 

Introduction to N-API

N-API is an API for building native plugins. It is independent of the underlying JavaScript runtime and maintained as part of Node.js itself. The purpose of this is to ensure that the Application Binary Interface (ABI) remains stable across Node.js versions.

 

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

Learn more about N-API .

 

Buffer safety improvements in Node.js 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, the new Buffer instance may contain sensitive information, which can easily lead to security problems.

 

While this is a decision to improve the performance of creating new Buffers, it is not intended to be used by most people. So starting from Node.js 8, Buffers allocated using new Buffer(Number) or Buffer(Number) will be automatically filled by ZEROS.

 

Upgrading V8 to 5.8: TurboFan & Ingnition

With Node.js version 8, the underlying V8 JavaScript engine is also updated.

 

The biggest change for Node.js users is the introduction of TurboFan and Ignition. Ignition is the interpreter for V8 and TurboFan is the optimizing compiler.

 

"The combined use of Ignition and TurboFan has been in development for nearly 3½ years, and it represents the end result of the collective understanding of the V8 team, the result of the V8 team gathering measured JavaScript performance and carefully analyzing the shortcomings of Full-codegen and Crankshaft. It is also The foundations of being able to continue optimizing the JavaScript language stack for years to come." - Daniel Clifford and the V8 team

 

The current V8 compilation pipeline is shown in the figure below.

The biggest problem with this pipeline is that new language features have to be implemented in different parts of the pipeline, which adds a lot of extra development work.

Here is the simplified pipeline without the FullCode Generator and Crankshaft:

 

The new pipeline greatly reduces the technical burden on the V8 team and enables many improvements that were not possible before.

Learn more about TurboFan and Ignition  and  TurboFan Inlining Heuristics  .

 

Upgrade npm to 5.0.0

The new Node.js 8 release also ships with npm 5 - the latest version of the npm CLI.

Highlights of the new npm release:

  • A new standardized lockfile feature for compatibility across package managers (package-lock.json), and a new format and semantics for shrinkwrap
  • --save is no longer needed, as all installations will be saved by default
  • node-gyp now supports node-gyp.cmd for Windows
  • The new release will include sha512 and sha1 checks

 

Other notable changes in Node.js 8 release

Buffer

Buffer methods now accept Uint8Array as input

Child Process

  • Argument and Kill signal validation improved
  • Child Process method accepts Uint8Array as input

Console

Error event sending is now suppressed when using console methods

Domains

Native Promise instances are now domain-aware

File system

  • Utility class fs.SyncWriteStream has been deprecated
  • The deprecated fs.read( ) string interface has been removed

HTTP

  • Spilled cookie headers are concatenated into a string
  • The httpResponse.writeHeader( ) method has been deprecated

Stream

Stream now supports destroy( ) and _destroy( ) APIs

TLS

The rejectUnauthorized option now defaults to true

URL

Implementation of WHATWG URL, now fully supported by Node.js API

 

What's next for Node.js 8

The Node.js 8 release is exciting for us because it includes a lot of interesting enhancements, such as the Async Hooks API, which are difficult to grasp in the current state of documentation. We will start using the new version as soon as possible and provide users with a more detailed description of the new features as soon as possible.

 

Among the many products that support node.js, one worth mentioning is Wijmo , a collection of HTML5 and JavaScript development controls for enterprise application development. Whether your application is mobile, PC, or must support IE6, Wijmo Enterprise can meet your needs.

 

Original link: https://blog.risingstack.com/important-features-fixes-node-js-version-8/

Please indicate the source of the reprint: Grape City Controls

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326658527&siteId=291194637