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

89
Views
How to handle API calls to get data that will be used for all requests to a node js application

I am designing a node js application which will get requests from frontends web applications and serve them data. It also uses some third party APIs that requires some token. Previously the token was stored in a config file. So Previously we had something like this.

config.js

module.exports = {
    token: 'xxxxxxxxxxxx'}

CustomModule1.js

const configuration = require('./config');
let client = thirdparty1.createClient({
             token: configuration.token});
function BusLogic(param){
   client.relevantWork().then(
   //return data
)
}
module.exports.BusLogic = BusLogic;

index.js

const customModule = require('./CustomModule1');   
module.exports = function (context, req){
   customModule1.BusLogic(req.param).then(res => {
      //return frontEndData
   })
}

Now we are storing token in a secure third party vault which requires another api call so I changed the structure to below.

config.js

let vaultFetch = (param1){
   return getfromVault(param1)
}
module.exports = {
        token: vaultFetch('tokenData')}

CustomModule1.js

function BusLogic(param,client){
       client.relevantWork().then(
       //return data
    )
    }
    module.exports.BusLogic = BusLogic;

index.js

const customModule = require('./CustomModule1');   
module.exports = function (context, req){
   configuration.then(x => {
       thirdparty1.createClient({
             token: configuration.token}).then(client => {
                customModule1.BusLogic(req.param,client).then(res => {
                    //return frontEndData
                })
             })
       })
}

But as it so happens in case of multiple concurrent requests the api is taking a long time to fetch data. It may be caused because client is being created for every request. Is there a way to create client one time somehow by using a promise?

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!