What’s new in Node.Js v12

What's new in Node.Js v12
[yasr_overall_rating] 369 People voted 5/5

In this blog post, we are going to discuss what is new with Node JS v 12 and discuss the new features that have been implemented with this version of Node JS. We are also going to compare this version with all the older versions and see how the latest version is the best one to go forward with.

 

Node JS continues to go forward with the yearly release cycle V 12. Since this is an even-numbered release, it will go into the LTS support option beginning October 2019 and is expected to reach its end of life on April 2022.

 

Node JS is packed with great trustworthy features and notable upgrades to the runtime, In addition to this, because the Node JS  makes use of the Google Chrome’s V8 Engine, it is going to receive all the latest updates from that as well.

 

Import Export statements are going to be supported (no bundler will be required)

With this version, Node JS enters the third phase for the ECMAScript modules. This corresponds to the path to the stability amongst modules inside the NODE. For the time being, it will still be behind the –experimental-modules flag, and the current plan among the developers of Node is to remove the flag by the time Node 12 goes into LTS in October.

Must Read: AngularJS vs Node JS

The import/export syntax has become the most preferred module syntax for JavaScript developers since its standardization is ES6 and the backend node team has been working diligently in order to enable it natively. Experimental support had begun for Node 8.0 at phase 0 and is about to take the major step with the newest Node release. All major Browsers gave their support to ECMAScript modules via the <script type=” module”> so this is indeed a huge update for Node

 

Phase 3 is going to add support for the 3 types of import from ES modules files, and it works with all the built-in Node Packages.

 

// default exports

import module from ‘module’

 

// named exports

import { namedExport } from ‘module’

 

// namespace exports

import * as a module from ‘module’

 

If you’re going to import from a CommonJS package, you can only import using the default export syntax import module from ‘cjs-library’

 

You can also use the import() expression to load any files at runtime. The import syntax returns a promise object and works with both ES modules and CommonJS libraries

 

V8 Engine

 

Node 12 is slated to initially run on the 7.4 version of the V8 engine and is going to eventually upgrade to version 7.6 during its lifetime. The V8 Team has agreed to provide Application Binary Interface (ABI) stability for this range of versions. Notable improvements for the 7.4 version of V8 include performance updates for providing faster execution of  JavaScript, better memory management as well as broadened ECMAScript syntax support

 

Here are some more features that the V8 engine provides:

 

  • Asynchronous stack traces
  • The JavaScript parsing is done swiftly
  • Argument mismatch calls are done faster
  • Faster await

 

Private Class Fields

It is reported that Node 12 will ship with private class fields, this is enabled by the V8 Engine. Private class field variables are only accessible only within the class itself and not from outside the class or exposed externally. A private class field variable is declared by using the # symbol before the variable name

 

class Greet {

 #name = ‘World’;

 get name() {

   return this.#name;

 }

 set name(name) {

   this.#name = name;

 }

 sayHello() {

   console.log(`Hello, ${this.#name}`);

 }

}

 

In the above example if you try to access the #name variable outside the class you will receive the following syntax error.

 

const greet = new Greet()

greet.#name = ‘NewName’;

// -> SyntaxError

console.log(greet.#name)

// -> SyntaxError

 

Improved Startup Performance

It is expected that Node 12 will have a code cache mechanism built into itself. Node 12 will build a code cache for built-in libraries before build time and embed it as a binary. The main thread is expected to use this code cache and improve startup time by 30%

 

TLS and Security

The node will now support TLS 1.3 which offers increased and heightened security and reduces latency. TLS 1.3 has been a huge update to the protocol and is actively being integrated across the web. By implementing TLS 1.3, Node apps will have increased end-user privacy while also improving the performance of requests by reducing the time required for the HTTPS handshake. In addition, TLS 1.0 and 1.1 have been disabled by default, and the crypto library has removed deprecated functions.

 

Heap Size Improvements

Previously the default V8 heap sizes were used which corresponded to 700MB (32-bit systems) or 1400MB (64-bit systems). The node will now determine the heap sizes based on the available memory which will ensure it does not use more than the resources allowed.

 

Heap Dump Functionality

Node 12 provides the ability to generate a heap dump making it easier to investigate memory issues.

 

Experimental Diagnostic Reports

Node offers improved ability to diagnose issues (performance, CPU usage, memory, crashes, etc) within applications by providing an experimental diagnostic report feature.

 

Native Modules N-API Improvements

The goal of N-API was to provide a stable native Node Module system. This system would prevent libraries from breaking on every release by providing an ABI-stable abstraction over native JavaScript APIs. Node 12 offers improved support for N-API in combination with worker threads.

 

Other Notable Improvements

  • Worker Threads no longer require a flag
  • http has updated its default parser to be llhttp
  • assert validates required arguments and adjusts loose assertions
  • buffer improvements to make it more stable and secure
  • async_hooks removes deprecated functionality
  • Make global. process, global.Buffer getters to improve the process
  • A new welcome message for repl

Conclusion

The Node team works very hard to provide yearly updates with huge improvements to the Node and the overall JS ecosystem, and version 12 does not disappoint.

 

2019 has been a big year for the Node application with the Node.js Foundation merging with the JS Foundation to form the OpenJS Foundation. We will wait for the Node JS to become mainstream in October 2019

 

If you are looking to hire NodeJS developers to design your new website or business Idea, do give us a call, we will be glad to assist you. You can also hire developers in Dubai, UAE.

Author

  • A technology enthusiast with over 14+ years of hands-on experience in the IT industry, I specialize in developing SaaS applications using Microsoft Technologies and the PEAN stack. I lead a team of 300+ engineers, holding multiple Microsoft certifications (MCSD, MCTS, MCPS, MCPD). My expertise spans across C#, ASP.NET, NodeJS, SQL Server, and Postgres.

    View all posts

Accelerate Success, with Innovative Software Solutions.

By submitting this form, you agree to our Privacy Policy

Related articles