An example only to verify from which node version Async/Await is supported without a feature flag.
Example: async_greeting.js
(async () => {
const msg = await asyncGreeting('This is an async greeting!')
console.dir(msg, { colors: true })
})()
async function asyncGreeting(str) {
return new Promise(resolve => setTimeout(() => resolve(str), 1000))
}
a. Async/Await feature is not supported without a feature flag in Node v7.5.0 or lower.
~> fnm use 7.5.0
~> node index.js
/home/joseluisq/async_greeting.js:1
(function (exports, require, module, __filename, __dirname) { (async () => {
^
SyntaxError: Unexpected token (
at Object.exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:543:28)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:418:7)
at startup (bootstrap_node.js:139:9)
at bootstrap_node.js:533:3
b. Async/Await feature is supported without a feature flag in Node v7.6.0 or above.
~> fnm use 7.6.0
~> node index.js
'This is an async greeting!'
* To see all node versions check out http://nodejs.org/dist/