Nodejs v7.6.0 release would support async/await

Node.js v7.6.0 is just released

Node.js v7.6.0 release change log: node/ at master · nodejs/node · GitHub

One of the shining change is that this release contains V8 engine 5.5.
V8 engine is the javascript engine which node.js is underlining using. With V8 engine 5.5, it would support async/await features. ( V8 JavaScript Engine: V8 Release 5.5 )

Async programming – Promise/async & await

In Javascript/node.js, there are multiple ways to dual with async programming.
With ES2016, people can use Promise syntax.
And with ES2017, people can use async/await syntax.

Promise style async programming:

function logFetch(url) {
  return fetch(url)
    .then(response => response.text())
    .then(text => {
    }).catch(err => {
      console.error('fetch failed', err);

Equivalent async/await style async programming:

async function logFetch(url) {
  try {
    const response = await fetch(url);
    console.log(await response.text());
  } catch (err) {
    console.log('fetch failed', err);

Why async/await is better than Promise?

There are multiple advantages:

  • The async/awwait style is much cleaner with less coding block/scopes. Promise would wrap the codes in difference function scopes.
  • We can use try catch to catch errors for sync/async codes.
  • Less lines. The general coding style of most people usually need several lines to write a wrapping function.




Node.js actually support async/await since v7, but it is locked in harmony flag until v7.6.0.

Leave a Reply

Your email address will not be published.