DEV Community

Cover image for What are the new improvements and features in Node 12
Harshal Suthar
Harshal Suthar

Posted on • Originally published at ifourtechnolab.com

What are the new improvements and features in Node 12

Introduction

"In early April, Node published version 12 (codename Erbium) that provides enhanced support for ECMAScript modules.". It implements phase 2 of the plan that was released in 2018 as it's Node v12 (this is as even-numbered version) which comes under Long term support start from October 2019 & will receive assistance until 2022, it will also be packed with a V8 motor maintained by Google in order to obtain future updates.

Major features of Node 12

  1. Out of the box is provided a produced heap dump capacity to investigate memory issues
  2. Increasing the startup time by 30 percent for the primary thread, Node.js 12 produces code cache in advance for built-in libraries, embedding it into the binary. The primary thread in the final release can use the software cache to begin the original load of any JavaScript-written built-in library.
  3. The heap size of JavaScript will be configured depending on accessible memory instead of using defaults set for the browser used by the V8 JavaScript engine
  4. Based on the available memory, configuring the heap ensures that Node.js does not attempt to use more memory than is available. Users can still set their default limit by using —max-old-space-size.
  5. TLS (Transport Layer Security) 1.3 because of the default max protocol. If necessary, CLI / NODE OPTIONS switches are endorsed to disable TLS. TLS 1.3 is a major update to the protocol.
  6. Updated experimental support for ECMAScript 6. This is a step toward a supported implementation.
  7. The default parser switches to llhttp. Testing the new llhttp implementation will be easier.
  8. Worker Threads use no longer needs a flag to be used.
  9. To produce a report on demand when certain occurrences occur, an experimental diagnostic report function is included. This can help diagnose manufacturing issues like accidents, slow performance, memory leaks, or heavy use of CPU.
  10. The codebase now needs on systems other than macOS and Windows a minimum of GCC (GNU Compiler Collection) 6 and glibc2.17.

Read More: Things To Be Considered In Nodejs 14 Release

Private class fields

JavaScript introduced the notion of personal class fields that ended up in Node.js v12. Simply offer them a name to mark personal areas beginning with #.

class IncreasingCounter {
#count = 0;
get value() {
console.log('Getting the current value!');
return this.#count;
}
increment() {
this.#count++;
}
}

Enter fullscreen mode Exit fullscreen mode

One obstacle!! If you are trying to access a private field outside of the calls it throws a SyntaxError error!

What's this about # in Private class fields?

is the new _. Whereas

class A {
_hidden = 0;
m() {
return this._hidden;
}
}

Enter fullscreen mode Exit fullscreen mode

Create a class with a convention-hidden field, but in reality it is completely public,

class B {
#hidden = 0;
m() {
return this.#hidden;
}
}

Enter fullscreen mode Exit fullscreen mode

Create a class with a field that is privately owned by the class, with language enforced privacy.

Improved Startup Performance

Node 12 will build a code cache for built-in libraries before build time and embed it as a binary. This code cache can be used by the primary thread to improve start time by 30 percent

TLS and Security
Node now supports TLS 1.3, providing enhanced safety and decreased latency. TLS 1.3 has been a large update to the protocol and is actively being integrated across the net. By implementing TLS one.3, Node apps can have exaggerated end-user privacy whereas additionally up the performance of requests by reducing the time needed for the HTTPS handshaking. Also, TLS 1.0 and 1.1 have been disabled by default, and the crypto library has removed deprecated functions.

Heap Dump Functionality
Node 12 offers the capacity to create a heap dump that makes memory problems simpler to explore.

Experimental Diagnostic Reports
Node provides an enhanced capacity to diagnose problems within apps (performance, CPU usage, memory, crashes, etc.) by offering an experimental reporting feature.

Native Modules N-API Improvements
N-API was released to provide a more stable and native Node module system that 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

  1. Worker Threads no longer require a flag
  2. The default parser of Http was updated to llhttpassert validates required arguments and adjusts loose assertions
  3. Upgrades to create it more stable and safeasync_hooks remove deprecated functionality
  4. Make global.process, global.Buffer getters to improve the process
  5. A new welcome message for reply

New compiler and platform minimums

Node.js and V8 still embrace newer C++ options and make the most of newer compiler optimizations and security enhancements. The codebase now needs at least GCC 6 and Glibc 2.17 on systems other than macOS and Windows with the launch of Node.js 12.

One Stop Solution for Nodejs Software Development - Enquire Today

The increment in minimum compiler and libc needs additionally increments minimums in supported platforms. Platforms exploitation Glibc (most platforms apart from macOS and Windows) should currently embrace a minimum version of 2.17. Common Linux platforms compatible with this version include Enterprise Linux 7 (RHEL and CentOS), Debian 8 and Ubuntu 14.04. These systems will be consistent with the binaries accessible from nodejs.org. Users needing to compile their binaries on systems not natively supporting GCC 6 may need to use a custom toolchain.Windows minimums stay an equivalent as Node.js 11, requiring at least Windows 7, 2008 R2 or 2012 R2 and a minimum compiler of Visual Studio 2017. macOS users needing to compile Node.js will require a minimum of Xcode 8 and Node.js binaries made available on nodejs.org will only support a minimum of macOS 10.10 “Yosemite”.

Heap Dump

If you ever required to come up with heap dumps to analyze memory problems however were stalled by having to put in a brand new module into production, the good news Node.js 12 takes the built-in heap dump capacity out of the box.This flag allows heap snapshots to be captured without modifying the application code. IMO, this is a big part of the "heap dump in core" use case.

It adds v8.heapdump.getHeapdump() and v8.heapdump.triggerHeapdump(filename) methods with impl adapted from the node-heapdump module.

Diagnostic Reports

This utility tool is known as node-report that was recently brought into the Node.js core. It helps to detect abnormal terminations, memory leaks, high CPU usage, unexpected errors and more in Nodejs development.

Run the node --experimental-report --report-on-fatalerror index.js to get a JSON summary on native stack traces, heap statistics, resource usage, etc.

Node.js got a bunch of diagnostic utilities within the recent versions to help the investigation on errors and bottlenecks that area unit troublesome to pinpoint. If you would like to form runtime statistics of the heap usage you'll try this by occupation v8.getHeapSnapshot() that was added in v11.13.0.

Conclusion

To provide yearly updates with huge improvements to the Node and the overall JS ecosystem, the Node team works very hard. The full CHANGELOG will be found on GitHub and extra details on the official release article. 2019 has already been an enormous year for Node with the Node.js Foundation merging with the JS Foundation to form the OpenJS Foundation.

Top comments (1)

Collapse
 
preethiashok05 profile image
Preethi

latest version of node is v20 , why does the blog consist features of v12 and calling it new improvements ?