Tutorial

What's New in Node 10 "Dubnium"

Draft updated on Invalid Date
Default avatar

By Samuel Oloruntoba

What's New in Node 10 "Dubnium"

This tutorial is out of date and no longer maintained.

Introduction

Node.js 10.0.0 is the seventh major Node.js release since the launch of the Node.js Foundation. In October of 2018, it will become the next Active Long Term Support branch.

Node.js version 10 is out. Yay!! This is the next LTS (Long term support) version of Node codename “Dubnium” (it’s a rare radioactive element and the most stable isotope in nature, probably a nod to the stability of Node.js v10).

You can also keep up with the release of Node.js.

There are quite a few cool features with this release so let’s just jump into it.

Stable HTTP/2

HTTP/2 support was first released in version 8 of Node. The initial release was a bit buggy, but with this version comes stability of HTTP/2 in Node.

Currently, Hapi and Koa support HTTP/2 in Node v10, but you can still use express-http2-workaround for express.

Let’s see a quick example of how to HTTP/2 in Node using Hapi.js:

const fs = require('fs')
const Hapi = require('hapi')
const http2 = require('http2')

const server = new Hapi.Server()
server.connection({
  listener: http2.createServer(),
  host: 'localhost',
  port: 3000
})

server.route({
  method: 'GET',
  path:'/hello',
  handler: function (request, reply) {
    return reply('Hello, World!')
  }
})

server.start((err) => {
  if (err) console.error(err)
  console.log(`Started ${server.connections.length} connections`)
})

Better support for ESM modules

Node came with its own module system and it’s what we’ve used for years. Node’s module system is called CommonJS (you’ve probably heard of it).

However, CommonJS is not quite common as it’s only suited to the Node environment. If you try to run a CommonJS file in the browser, you’ll get a barrage of red flags in devtools.

Along comes ECMAScript 6 which brought a module system to JavaScript. With this release, Node.js supports this module system.

What this means is that we can now do stuff like

import { resolve } from 'path'

and

export { default } from 'os'

For this to work, you need to adhere to the new .mjs file naming convention. You can read all about it on Gil Tayar

We also get a standardized global object (window alternative)

Standardized error codes

Before v10, once a new or strange error occurred, we literally had to copy-paste the message in Google and rely on their impeccable ability to find your answer in StackOverflow’s archive.

With this release, all errors in Node.js have a code attached to them. This gives us more error handling power and flexibility and removes a lot of guessing from your StackOverflow game. Node Foundation did a better job explaining it, so go check it out.

N-API is no longer experimental

If you don’t know what N-API is let me explain.

N-API is an API for building native Addons

You don’t have to know any C or C++ to do this as it is a part of Node.js. It is intended to insulate Addons from changes in the underlying JavaScript engine and allow modules compiled for one version to run on later versions of Node.js without recompilation.

It was first released in Node v8, but it’s now stable to use.

V8 and OpenSSL updates

Node.js runs on the V8 JavaScript engine, the same engine that runs Google’s Chrome. With Node v10, V8 got an upgrade bump to v6.6. Doing this means that we now have support for async generators and iterators in Node. No transpilation or experimental flag necessary.

OpenSSL also got a bump to v1.1.0. This means that we have access to TLS 1.3 which allows faster SSL handshakes and more security. It also means we get the ChaCha20 cipher and Poly1305 authenticator.

npm v6

It’s not a Node update without npm. With Node v10 comes npm v6 and npm stepped up their game. This new release comes with

  • More focus on security, and npm has it baked in.
  • You can use the npm audit command to find security vulnerabilities.
  • I haven’t tested this out, but it claims to be 17x faster.
  • There are also npm optimizations for continuous integration (CI) environments so builds can run faster.
  • More visible integrity metadata for package tampering. etc.

New methods

New methods added to Node v10 include:

  • String#trimStart/trimEnd to remove unwanted characters either at the beginning or end of strings.
  • RegExp: s (dotAll) & u (unicode) flags, named captures, lookbehinds
  • Optional (e) in try {} catch(e) {}
  • Finally, console.table.
  • EventEmitter.prototype.off() will serve as an alias for EventEmitter.prototype.removeListener()
  • The WHATWG URL API is now a global. Meaning we have access to the same URL API as the browser.

Deprecations

  • Using require() to access several of Node.js’ own internal dependencies will emit a runtime deprecation.
  • The crypto.createCipher() and crypto.createDecipher() methods have been deprecated.
  • Passing more than one argument to assert.fail() will emit a runtime deprecation warning
  • Use of non-string values for process.env has been deprecated in the documentation.

Conclusion

That was a quick wrap of what’s new in Node.js v10. You can read the official changelog for more information on this release.

Below are also a few resources you could check for more information.

Have a great day. Oh! let us know your thoughts on this release in the comments. What’s the most exciting feature?

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about us


About the authors
Default avatar
Samuel Oloruntoba

author

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
Leave a comment


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel