March 26th 2017

Node.js v7.6.0 with async/await

The Eventn platform now supports Node.js v7.6.0. This is a significant release in that it contained an update to V8 to v5.5 (Node's underlying JS engine from Google). The v8 releases adds support for async functions utilizing theasyncandawaitkeywords.

This new async capability looks to simplify promise based code making it much more readable. Instead of usingPromise.then()chains, wrapping a function with theasynckeyword,awaitcan then be called similar to how a synchronous function would be used.

Here is a simple example of calling an asynchronous Promise based function using async/await within an EventnonGet()function:

const rp = require('request-promise');

async function onGet() {
const options = { uri: 'https://www.google.com', json: true };
try { return await rp(options); } catch (error) { return error; } }
module.exports = onGet;