Node JS 12 Features & improvements

Node JS continues through its yearly release cycle with Version 12, which is code-named as erbium. Since the version is even-numbered, it’ll enter as long-term Support (LTS). It begins in Oct 2019 and spans until April 2022.

Node 12 comes with notable options and runtime upgrades. Node uses the V8 engine from Google, found in Chrome, and can incorporate the updates from that too.

Let us explore the options in Node 12

V 8 Engine

A new version for V8 JavaScript Engine. It not only brings performance tweaks however has in progress enhancements for Node.js in areas of runtime and language. Some highlights can be

Async Stack Traces
Faster Parsing of JavaScript
Faster Calls with Arguments mismatch
Faster look
Node 12 can at the start run with V8 7.4 and afterward upgrade to 7.6. The V8 team has prearranged API (Application Binary Interface) stability for the higher than vary. some of the noteworthy enhancements with V8 7.4 are

Better Memory Management
Performance updates to confirm quicker JavaScript execution.
Broader ECMAScript Syntax Support

JavaScript Language Options

ASync Stack Traces

Till recently, the developers faced problems in truncating the stack trace until the recent look. the newest update permits Node.js to trace the asynchronous decision frames in error. stack property.

Here may be a code snipping to point out the higher than feature

async function wait_pizzaready(x) {

await wait_makesauce(x);

}

async function wait_makesauce(x) {

await wait_makedough(x);

}

async function wait_makedough(x) {

await x;

}
throw new error (“Oops”)
}

wait_1(1).catch(e => console.log(e.stack));

Private class Fields

Node 12 comes with a personal category field, accessed from inside the category itself, and not exposed outwardly. it’s declared by prepending the variable with a #image.

Here may be a code snipping to point out the higher than feature:

lass foo
{
# b = 20;
get( )
{
return this.#b;
}
increment
{
++this.#b;
}
}

The private class field throws a syntax error if access #name outside the class

const foo = new foo()
foo.#name = ‘NewName’;
// -> SyntaxError
console.log(foo.#name)
// -> SyntaxError

Public class Fields

The new public class field simplifies the class definition. The listing of default values of a variable within the creator, it defines them within the category level.

class IncreasingCounter {
_count = 0;
get value() {
console.log(‘Getting the current value!’);
return this._count;
}
increment() {
this._count++;
}
}

The -count variable gets outlined on the high of the category. there’s a necessity for a creator to outline fields. Here the -count field acted as property and prevented from accessing the property directly.

TLS and Security

TLS (Transport Layer Security) one.3 is supported by Node 12 for reduced latency and augmented security. It actively integrates across the net. The Node apps can have augmented end-user privacy by implementing TLS one.3. It additionally helps to boost the performance of requests, thereby reducing the time for HTTPS shake. additionally, to the current, the crypto library has removed deprecated functions and TLS one.0 and 1.1 disabled.

Supporting Import/Export Statement (No Bundler Required)

There is a path to the steadiness of modules within Node 12 with section three of the ECMAScript Modules. The import/export syntax is that the preference of the JavaScript developers, since its standardization in ES6.

The experimental support on this feature started from Node eight.0 section zero and has taken a leap forward in Node 12. ECMAScript modules get support from all the main browsers, through the

Three sorts of imports are potential from the metal module files, operating with all intrinsic Node packages by section three of the ECMAScript Modules.

You can import victimization the below export syntax whereas commercialism from the CommonJS package. The import syntax returns a promise and works with ESModules and CommonJS libraries. Files will load at runtime with dynamic import expressions.

Read also: The Benefits & Drawbacks of Node JS Web Development

Heap Size enhancements and Heap Dump practicality

In the previous releases for Node, unless designed, V8 had a default for max heap size to 700 MB or 1400 MB on a thirty-two or 64-bit platform, severally. The update configures the JavaScript heap size on the market memory rather than defaults set by V8, utilizing for the browsers.

While configuring the heap size supported memory, it gets ensured that Node.js doesn’t attempt to use memory, quite that on the market. It equal with memory exhaustion. The update becomes helpful for the process of enormous information sets.

furthermore, Node 12 brings the integrated heap dump capability – out of the box. It makes it easier to research memory problems.

Improvements in Native Modules and N-API

N-API provide native Node modules, for a native Node module system with stability. It offers ABI-stable abstraction over the native JavaScript genus Apis, by preventing breaking down of libraries in each unleash. N-API offer improvement in support to N-API, combining with employee threads.

Improvement in Startup Performance

In the previous version, Node.js 11 offers intrinsic code case support in staff. If any compilation of the library, within the main thread, then there’s no want for a compilation of the employee thread, instead reprocess the V8 Code cache, made by the most thread, and speed up compilation. Similarly, you will reprocess the cache generated by the staff. It provides an hour acceleration for the startup of staff.

Now Node 12, permits building the code cache for intrinsic libraries before, at build time, and embeds within the binary. It helps within the final unleash. the most thread uses the code cache to start out the initial load for any intrinsic JavaScript library. It provides a quicker startup time for the most thread, by 30 %.

Switch Default HTTP parser to llhttp

In this category, the default parser switches to llhttp. It permits a comparison of llhttp-based implementation and testing easier.

Diagnostic Reports

There is a beneficial tool node-report brought into the node.js core. The report helps in memory leaks, high hardware usage, sudden errors, and detection of abnormal terminations.

In the gift versions of Node, several diagnostic utilities facilitate the detection of errors and any bottlenecks, arduous to pinpoint.

You get a JSON outline on heap statistics, resource usage, native stack traces by running:

node — experimental-report — report-on-fatal error index.js

If the developer needs to urge runtime statistics on heap usage, then decide the subsequent – other in v11.13.0.

v8.getHeapSnapshot()

Conclusion:

Node team value-added some nice options in their v 12 which is able to undoubtedly facilitate the Node JS Development method and a few options like progressing to embody Python 3 support, rising startup performance, Core Promise API support, any work on standards and governance, and a replacement Streams API are going to be landing within the new node release.

Share this Article