Skip to content

Instantly share code, notes, and snippets.

@joseluisq
Last active April 19, 2018 07:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joseluisq/73e8809af03d4a788ddd90ffc1b211db to your computer and use it in GitHub Desktop.
Save joseluisq/73e8809af03d4a788ddd90ffc1b211db to your computer and use it in GitHub Desktop.
An example only to verify from which node version Async/Await is supported without a feature flag.

Verify NodeJS Async/Await support

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment