Home > Blockchain >  node.js request(get) result return
node.js request(get) result return

Time:07-18

I want to return the result obtained from the request.

The code does not produce the desired result.

Please help me

CODE

const getData = async (gn) => {
  let gameData = undefined;

  gameData = await rq({
    method: "GET",
    url: base_url   "/get_gameData/OXquiz",
  }).then(function (response) {
    return response;
  });

  return gameData;
};

console.log(getData("OXquiz"));

RESULT

Promise { <pending> }

The result I want

{"status":0,"message":[{"ga_win_point":"100","ga_lose_point":"50","ga_time":"10","ga_max_number":"8"}],"url":""}

CodePudding user response:

try

getData().then(item => console.log(item))

or

const data = await getData()

CodePudding user response:

Why are you using await and .then at a time. If you want to work asynchronously use the following snippet.

const getData = async (gn) => {
  let gameData = undefined;

  gameData = await rq({
    method: "GET",
    url: base_url   "/get_gameData/OXquiz",
  });

  return gameData;
};

console.log(getData("OXquiz"));
  • Related