I'm trying to use aysnc and await in my project,
I first tried these in FiddleJS, and it works fine but when I tried to do it in my IDE (PHPSTORM 2017) I got an error:
async function test(url){
^^^^^^^^
SyntaxError: Unexpected token function
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:389:7)
at startup (bootstrap_node.js:149:9)
I also tried on vscode and got the same error.
Here is what I tried to do:
async function test(url){
console.log(await check(url) );
}
app.get('/test', (req, res) => {
var url = req.query.url;
console.log(url);
test(url);
console.log(url)
});
function check(url){
console.log(url);
return new Promise( (resolve, reject) => {
request(url, function (error, response, body) {
if(response.headers.server === 'test'){
url = url + '123';
resolve(url);
} else {
reject('error');
}
});
});
}
As I said, in FiddleJS it working fine (https://jsfiddle.net/voogcrbf/2/), don't know why there is an error in the IDE's.
Hope you could help me with that.