This tutorial is out of date and no longer maintained.
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.
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`)
})
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)
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.
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.
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.
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
npm audit
command to find security vulnerabilities.New methods added to Node v10 include:
String#trimStart/trimEnd
to remove unwanted characters either at the beginning or end of strings.s
(dotAll) & u
(unicode) flags, named captures, lookbehinds(e)
in try {} catch(e) {}
console.table
.EventEmitter.prototype.off()
will serve as an alias for EventEmitter.prototype.removeListener()
require()
to access several of Node.js’ own internal dependencies will emit a runtime deprecation.crypto.createCipher()
and crypto.createDecipher()
methods have been deprecated.assert.fail()
will emit a runtime deprecation warningprocess.env
has been deprecated in the documentation.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.
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!
Enter your email to get $200 in credit for your first 60 days with DigitalOcean.
New accounts only. By submitting your email you agree to our Privacy Policy.