Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

221
Views
How to return the token as a value? Node js

How can I solve this problem? I made a post request to get the token, but when I return it, it returns as undefined, but when I print it, it shows the token OK.

function getToken() {

  // The req.query object has the query params that
  // were sent to this route. We want the `code` param
  axios({
    // make a POST request
    method: "post",
    // to the Github authentication API, with the client ID, client secret
    // and request token
    url: ` https://backstage.taboola.com/backstage/oauth/token?client_id=${clientID}&client_secret=${clientSecret}&grant_type=client_credentials`,
    // Set the content type header, so that we get the response in JSOn
    headers: {
      accept: "application/json",
    },
  }).then((response) => {
    // Once we get the response, extract the access token from
    // the response body
    accessToken = response.data.access_token;
    //console.log(accessToken);
    return(accessToken);
  });
};
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You could do something like this

async function getToken() {

  // The req.query object has the query params that
  // were sent to this route. We want the `code` param
  const response = await axios({
    // make a POST request
    method: "post",
    // to the Github authentication API, with the client ID, client secret
    // and request token
    url: ` https://backstage.taboola.com/backstage/oauth/token?client_id=${clientID}&client_secret=${clientSecret}&grant_type=client_credentials`,
    // Set the content type header, so that we get the response in JSOn
    headers: {
      accept: "application/json",
    },
  });
  return response.data.access_token
};

const token = await getToken();
console.log(token)
// more https://www.w3schools.com/js/js_promise.asp
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!