0

I am attempting to assign the body of the callback function to assign it to a variable.

const request = require('request');


async function getAPIToken(options){
    let token = await request(options, (error, response, body)=> {return body})
    return token
}

let token1 = getAPIToken(options);
console.log(token1)

This returns promise pending, however when I use token1.then((a)=> {console.log(a)}) it returns the request not the body.

user5067291
  • 375
  • 4
  • 13
  • Did you read about `async/await` support in `request` package here: https://www.npmjs.com/package/request#promises--asyncawait ? – Anatoly May 22 '21 at 11:43
  • Also please pay attention that `request` package is deprecated. I recommend you to use something like `axios` or `got` – Anatoly May 22 '21 at 11:44

0 Answers0