Jump to content


wait for return value of function

  • Please log in to reply
No replies to this topic

#1 tvman99



  • Member
  • Pip
  • 7 posts

Posted 27 September 2018 - 09:46 AM

I have a function which checks the input is in json data from url. How can i implement async await into it? I've got no success. All my attempts were returning pending promises.

function checkUser(id){
	var url = 'http://mywebsite.com';
	var jsonObject;
	request(url, function (error, response, body) {
		if (!error && response.statusCode == 200) {
			jsonObject = JSON.parse(body);
			if (jsonObject.hasOwnProperty(id))
				return jsonObject[id];
				return 0;

Also tagged with one or more of these keywords: Question

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users