Node 8: Five New Features You Need to Know

The reason of the delay is actually a performance concern: because of the staggered release, the Node team is able to ship version 8 with an updated V8 engine featuring a more modern compiler + jit pipeline.

Version 8 is important as later this year (in October) Node 8 will be LTS, so it's worth checking out its new features compared to the previous LTS (v6) and the previous stable (v7) release.

Let’s get started! 🚀

Five Node 8 Features:

1. String padding

v6: no ⛔

v7: harmony 💛

v8: yes 💚

PadStart and PadEnd functions are basically string utility functions which are already used by the majority of JavaScript developers today, provided by various libraries such as lodash.

In fact, one time padStart (or as they called it left-pad) was unpublished from NPM and lots of packages broke that day that depended on it (like React or Babel).

2. Trailing comma in parameter + arguments

v6: no ⛔

v7: no ⛔

v8: yes 💚

In early Node versions (0.X) the support for object and array trailing commas were already implemented, making multiline object and array definitions much more friendly towards extension and version control.

In Node 8 this support arrived for function parameters and function arguments too. From now on, the definition and invocation of multiline parametered functions will now also be extension and version control friendly.

3. Async functions

v6: no ⛔

v7.5: harmony 💛

v7.10: yes 💚

v8: yes 💚

Back in 2015, when Node 4 was introduced, generators were implemented from the ES2015 standard. With a package called co we could utilize generators to write better asynchronous code, by ‘yielding’ promises instead of chaining them with ‘then’, creating a more readable control flow.

The async/await feature brings this approach to a new level. This control flow can be implemented without the need of a third party library. Instead of generator functions we use async functions, and instead of the yield keyword we use the await keyword.

4. Template literal revision (ES2018)

v6: no ⛔

v7: no ⛔

v8: harmony 💛

Template literals were introduced in the ES2015 standard. It is really useful when it comes to string interpolation, however there are some special unicode characters, such as \u or \x that cannot be used in template literals.

The template literal revision aids this problem by allowing these special characters. A good use case can be found in the proposal document: the embedding of DSL languages (like LaTeX where \u or \x characters are common) can greatly benefit from this feature.

function latex(strings) {
// ...
}
latex`
\document{article}
\usepackage{somepackage}
`
// \document{article} works on previous Node versions
// \usepackage{somepackage} will only work on Node 8 due to ‘\u’ special character

5. Object rest and spread (ESNEXT)

v6: no ⛔

v7: no ⛔

v8: harmony 💛

Array rest and spread were already available in previous Node versions. Now in Node 8 the support for object rest and spread has landed.

Object rest gathers the non-destructured keys remaining in the object:

Bonus: NPM 5

Although not strongly coupled with Node, it's worth noting that NPM version 5 is out. Some cool features like automatic --save flag is applied upon package install, or the debut of package-lock.json lockfile. For the full feature list check out the NPM blog.

Conclusion

That’s it! With this post, we wanted to give you a list of the new Node 8 features to help you quickly review the most important changes. If there is anything new to add feel free to let us know in the comments below.