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

160
Views
Make request again if data is not received in 5 seconds NODEJS

My use case is that I want to make a request again, if the response is not received in 5 seconds. Below is my code, can you help me achieve that?

try {
    const details = {
        grant_type: "password",
        client_id: config?.ClientId,
        client_secret: config?.ClientSecret,
        username: config?.Username,
        password: config?.Password,
    };
    console.log('๐Ÿš€ ~ file: authenticate.js ~ line 17 ~ details', details);
    var formBody = [];
    for (var property in details) {
        var encodedKey = encodeURIComponent(property);
        var encodedValue = encodeURIComponent(details[property]);
        formBody.push(encodedKey + "=" + encodedValue);
    }
    formBody = formBody.join("&");
    const data = {
        url: `${URL}`,
        method: "POST",
        headers: {
            "Content-Type": "application/x-www-form-urlencoded",
        },
        json: true,
        data: formBody,
    };
    
    const response = await axios(data);
    console.log('๐Ÿš€ ~ file: authenticate.js ~ line 35 ~ response', response);
    return response.data;
}
catch (error) {
    console.log("Error While authenticating", error);
    return error
}
about 4 years ago ยท Juan Pablo Isaza
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!