2 min read

What's new in Node.js 6.0

This new release of node aims to improve performance, reliability, usability and security.

Node 6.0 supports 93% of ES6 features.

Only 6 months after Node Foundation announced version 5.0

Announcement can be found here;
https://nodejs.org/en/blog/release/v6.0.0/

Support for older versions

LTS (long-term support) of 4.0 until April 2017.

If you are using any of 0.12, 0.14, 5.* versions of node, you might want to consider upgrading.

October of this year (2016), Node.js v6.0 will be an LTS

Changes

I'm going to try and make important notes to save readers the time of digesting the official announcement.

Buffer

There is a new Buffer API that reduce the risk of bugs and vulnerabilities leaking into applications.

  • Buffer and SlowBuffer APIs.
  • Added lastIndexOf method to Buffer prototype chain.

New ES6 Features

Probably the most exciting part of the announcement.

Default Function Parameters

Node.js being JavaScript based, has to be the only programming language that didn't offer such a basic feature.

before 6.0

function functionWithDefaultValue(val) {
    val = val || {};
}

now in 6.0

function functionWithDefaultValue(val = {}) {

}
Spread Operator

This new sugar lets us extract each array item as function parameter. Before the spread operator, we would do something like this.

function myFunc(x, y, z) {

}

var args = [0, 1, 2];
myFunc.apply(null, args);

This is how you use a spread operator;

function myFunc(x, y, z) {

}

var args = [0, 1, 2];
myFunc(...args);

This may seem arguments-esq but check out this example;

function spreadDebug(a, b, ...spread) {
    console.log(a, b);
    console.log(spread);
}
spreadDebug(1, 3, 'unknown', 'params');

Destructuring

PHP devs will see this feature being similar to list() but lets take a look at some distinct examples;

Extract data from arrays (or objects) into distinct variables.

var x = [0, 1, 2, 3]
var [y, z] = x
console.log(y) // 0  
console.log(z) // 1 

Swapping variables

var a = 0;
var b = 99;
[a, b] = [b, a];
console.log(a); // 99
console.log(b); // 0
crypto

With this release there will be some breaking changes form Node.js v5.x

  • crypto.Certificate no longer has _handle property.
  • The digest parameter for crypto.pbkdf2() is now required.
  • The default encoding for all crypto methods is now utf8.
  • FIPS-compliant mode is now off by default even if node is built with FIPS-compliance.
events

The internal event handler storage object EventEmitter#_events now inherits from Object.create(null) rather than Object.prototype.
This prevents issues with events using otherwise reserved property names such as proto.
This also means that any properties that modules intentionally add to Object.prototype will not be available on _events.

Final words

Node.js is used by tens of thousands of organizations and amasses more than 3.5 million active users per month. It is the runtime of choice for high-performance, low latency applications, powering everything from enterprise applications, robots, API engines, cloud stacks and mobile websites.

Resources

Please spread the knowledge!