šŸ“œ ā¬†ļø ā¬‡ļø

Review of changes in the new major release Node 8


May 30, 2017 at 23:00 Moscow time, a new long-awaited major release Node.js 8.0.0 was released . It is this line of versions number 8 in October 2017 that will go to Long Term Support - a long support cycle. I offer you a small overview of the huge number of changes and additions included in this release.



The new major version marks the beginning of a new branch with a long support cycle. I will clarify what will happen in October 2017, together with the assignment of the code name Carbon, and this thread will be maintained until December 31, 2019. Node.js 6 will also go into support mode in April 2018 and end its life in April 2019.



npm 5.0.0


The new version of Node comes bundled with the new version of the npm package manager. Obviously, an unexpected competitor had a significant impact on npm developers: Yarn from Facebook.


The npm team did a great job of optimizing, refactoring the internal mechanisms and correcting a number of old architecture-related errors.


Here is an incomplete list of changes:



V8 5.8


The new version of JavaScript runtime engine V8 contains significant improvements in performance and accessible API. The developers guarantee that this version will contain ABI (application binary interface) compatible with upcoming versions of V8 - 5.9 and 6.0.


In 5.8 5.9, for the first time, the TurboFan optimizing compiler and the Ignition interpreter will be included by default, which were also available in the previous release. This promises us less memory consumption, and a significant optimization of try / catch ads, generators, and async functions. The same changes will fall into the next release of Chrome 59.


These changes were so significant that the Technical Committee of Node.js (Core Technical Committee) decided to postpone the release of 8.0.0, originally planned in April, to May.


N-API


N-API is an API for developing native add-ons, regardless of the underlying runtime JavaScript. The used ABI (application binary interface) will remain stable over several versions of Node. Thus, modules compiled for the same version will be executed on later versions of Node without recompilation.


async_hooks


This experimental module (previously known as async_wrap) provides developers with the ability to track the execution of the Node.js event loop. The API allows you to register callbacks that notify the consumer about the life cycle of asynchronous resources within the application interacting with the underlying C ++ code. Such asynchronous resources are responsible, for example, for TCP sockets, reading from a file, etc.


WHATWG URL parser


The experimental URL parser conforming to the WHATWG standard was added to version 7 of Node.js, and in the 8th prefix "experimental" was officially canceled. Now the implementation of the parser in Node coincides with that in modern browsers, which allows the code associated with the URL to be used both in the server and client environments.


Buffer security enhancement


Up to version 8 of Node.js, the buffer created using the Buffer (Number) constructor did not initialize the allocated memory with zeros. As a result, buffer instances could contain sensitive information. This vulnerability in the new version was eliminated; at creation, the buffer will be filled with zeros. Since this has a negative impact on performance, for cases where it is acceptable, the developers suggest using another API, Buffer.allocUnsafe (), which allows you to create an uninitialized buffer.


Simplified Promissification


Promissification is a wrapper over an asynchronous code that uses callbacks and returns promis. The function that performs promisification is, for example, in the popular bluebird library. Now in Node.js, its analogue for native promises has appeared: util.promisify (). Here is an example of its use:


const fs = require('fs'); const util = require('util'); const readfile = util.promisify(fs.readFile); readfile('/some/file') .then((data) => { /** ... **/ }) .catch((err) => { /** ... **/ }); 

Static error codes


The developers started the process of assigning static codes to all the errors generated by Node.js. Not all errors have yet received their code. The advantage of the codes is that they are guaranteed not to change even if the error changes the type or the message. You can get the error code in two ways:





From small, but pleasant bonuses: with the --harmony flag you can now use the rest property on objects :


 let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 } console.log(x) // 1 console.log(y) // 2 console.log(z) // { a: 3, b: 4 } 

As well as native methods (without --harmony) string.padStart () and string.padEnd (), because we all remember and grieve ...


PS Oh yes, and the most important innovation - when mentioning versions of Node.js, the developers abandoned the ā€œvā€ prefix: v0.10, v0.12, v4, v6. So that there is no confusion with the V8 engine, now it officially sounds like this: Node.js 8.



The following resources were used to prepare the article:



')

Source: https://habr.com/ru/post/329942/


All Articles