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)
}
}
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)
}
}
Share
Improve this question
edited May 6, 2018 at 18:28
SpecialVirusTasker
asked Jul 23, 2017 at 17:05
SpecialVirusTaskerSpecialVirusTasker
553 silver badges12 bronze badges
5
- 1 Is your node up to date? Async/await got enabled in node 7 I think. – Sirko Commented Jul 23, 2017 at 17:07
- oh shit bro im on 6.10 – SpecialVirusTasker Commented Jul 23, 2017 at 17:08
- You still have syntax errors on top of having a wrong version. – Darkrum Commented Jul 23, 2017 at 18:49
- and what are the errors? – SpecialVirusTasker Commented Aug 5, 2017 at 23:51
- see also stackoverflow./q/37815790/2969544 – oklas Commented Oct 21, 2017 at 21:43
2 Answers
Reset to default 7async function is supported officially in nodejs 8 and later. you should update your nodejs version to 8 or later.
Install node version manager:
curl -o- https://raw.githubusercontent./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