SyntaxError: Unexpected token function - Async Await Nodejs SyntaxError: Unexpected token function - Async Await Nodejs express express

SyntaxError: Unexpected token function - Async Await Nodejs


Async functions are not supported by Node versions older than version 7.6.

You'll need to transpile your code (e.g. using Babel) to a version of JS that Node understands if you are using an older version.

That said, versions of Node.js which don’t support async functions are now all past End Of Life and are unsupported, so if you are using an earlier version you should very strongly consider upgrading.


Node.JS does not fully support ES6 currently, so you can either use asyncawait module or transpile it using Bable.

install

npm install --save asyncawait

helloz.js

var async = require('asyncawait/async');var await = require('asyncawait/await');(async (function testingAsyncAwait() {    await (console.log("Print me!"));}))();