Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

90
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda