3

So I'm trying to use async/await but i get this error:

async function something(options) {
  ^^^^^^^^
SyntaxError: Unexpected token function

Here's the code:

var request = require('superagent');

async function something(options) {
    let response = await request.get("apiurlblabla");
    if(response) {
      .query(({'queryqeureur}))
      .query(({'uqeryqery'}))
      var jsonString = JSON.parse(res.text)
      console.log(jsonString.propertyblabla);
      console.log(jsonString.propertyblabla)
    }
}
5
  • 1
    Is your node up to date? Async/await got enabled in node 7 I think. Commented Jul 23, 2017 at 17:07
  • oh shit bro im on 6.10 Commented Jul 23, 2017 at 17:08
  • You still have syntax errors on top of having a wrong version. Commented Jul 23, 2017 at 18:49
  • and what are the errors? Commented Aug 5, 2017 at 23:51
  • see also stackoverflow.com/q/37815790/2969544 Commented Oct 21, 2017 at 21:43

2 Answers 2

7

async function is supported officially in nodejs 8 and later. you should update your nodejs version to 8 or later.

Sign up to request clarification or add additional context in comments.

Comments

1

Install node version manager:

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.6/install.sh | bash

Install new version of node:

nvm install 8.0

Update verion which uses:

nvm use 8.0

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.