JavaScript Journal

Subscribe to JavaScript Journal: eMailAlertsEmail Alerts newslettersWeekly Newsletters
Get JavaScript Journal: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn


JavaScript Authors: Sematext Blog, Klaus Enzenhofer, Mehdi Daoudi, Yakov Fain, AppDynamics Blog

Related Topics: Cloud Computing, Open Source Journal, JavaScript

Article

About Node.js 4.0.0 | @DevOpsSummit #API #DevOps #IoT #M2M

Node.js 4.0.0 aims to provide an easy update path for current users of io.js & node so there are no major/breaking API changes

What You Need to Know About Node.js 4.0.0

Now - that Node.js 4.0.0 was officially released - you may wonder what it delivers to you and if you should upgrade right away, or not. This post covers the most important changes you need to know, and some key implications you may have to take into account in making your decision.

The Story So Far
The last few months were really exciting for the Node.js community.

At the start of this year Joyent Inc. handed over the project to the community around io.js, a fork of Node.js. Soon after that, it was decided that there should be only one version that incorporates all current features of io.js and Node.js in the future.

Bringing together two codebases that drifted away from each other for many months is a huge endeavor. When I was told about it at NodeConf in June, initially I was pessimistic about the planned time frame of about 3 months.

I'm really stunned that actually a new converged Node.js 4.0.0 has just landed.

Why "4.0.0"?
The io.js project uses semantic versioning (semver) with its first major release being a 1.0.

The current main line of io.js is 3.x. To avoid collisions with the 0.x scheme of Node.js it was decided that the converged version should be a 4.0.0 and will also be following the semver scheme <major>.<minor>.<patch> from now on.

So ... What's New
Node.js 4.0.0 aims to provide an easy update path for current users of io.js and node and so there are no major/breaking API changes. Nevertheless there are many small improvements and changes. I recommend reviewing the the LTS Wiki (we'll speak about LTS further down) and running extensive tests before updating your production environments.

Let's review the most important changes.

New V8 Version (and Its Implications)
One reason for creating io.js in the first place were unpredictable and long release cycles.
Node.js and io.js heavily depend on Googles V8 JavaScript engine which is under constant development and improvement and the project was falling behind quickly.

Node.js 4.0.0 now uses a recent version of V8 (4.5 compared to 3.28.x in node 0.12, to be exact) - this is great because it offers new language features (see below) but comes with a cost:

Node.js projects usually heavily depend on modules. A fraction of them are native - this means that they are written in C++ and are linked against V8.

Without precautions every new V8 version will break all native modules. To remedy this, there is an abstraction library called Nan that provides Macros and an API for different versions of V8. So one module that uses Nan will usually work with all versions from 0.8 to 0.12.

With Node.js 4.0.0 Nan took the chance to do some refactoring and also bumped its version from 1.x to 2.x, introducing breaking changes.

This means that a native module needs to be modified to use Nan 2.x to work with Node.js 4.0.0.

For regular users of Node.js the consequence is that some native modules used their projects may cease to work if there is no update available. This might be a deal breaker for some but maybe this is also a chance to closely review all the modules used and look for actively maintained alternatives.

You are also free to fork modules and port them to Nan2. I just did this with node-gc-profiler. Here's also a diff that shows the changes that were necessary.

After covering the not-so-exiting implications let's look at what you get in return:

Extended ES6 support
ECMA-262 is the latest version of the JavaScript language specification and - by building on a recent V8 version - Node.js 4.0.0 supports many new language features out of the box.

Here are some examples

  • Block scoping using let and const
  • Classes. Yes really, JavaScript now supports classes but they are just syntactic sugar built around the prototypical inheritance model of JavaScript. So if you are using CoffeeScriptbecause you just can not live without having a ‘class' keyword this new feature is for you.
  • Generators (function*, next and yield) It makes sense to get used to- and understand them. They will be heavily used in the future. koa.js, for instance, was built by the express folks and heavily depends on them.

Please find a complete list of currently supported ES6 features here: ES6 in Node.js 4.0.0.

Performance
I've run some benchmarks using express with Node.js 0.10, 0.12 and 4.0.0 and I was really hoping that I could provide some exiting performance gains but the truth is ... well let's look at it.

This is no longer true. I ran my initial performance tests against an early release candidate and there were no significant performance gains. After release candidate 4 introduced improved V8 ArrayBuffer handling I redid my tests with the final release and now ... well let's look at it.

For my tests I used a simple express application and created some load using ab.

First I wanted to know the difference in request performance and collected the number of requests per second and the time a single request took.

Figure 1: Overall performance of Node.js 4.0.0 compared to 0.12 and and 0.10

Click here for the full article

More Stories By Daniel Khan

Daniel Khan has over 15 years experience as full stack developer, architect and technical lead in the field of web engineering proving his strong problem solving skills in hundreds of projects. He is passionate about constant learning, using new technologies and sharing his findings with others. As technology strategist, Daniel focuses on driving support for emerging technologies like Node.js and MongoDB at Dynatrace.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.