Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

128
Visualizações
Add extra context to fetcher method from outside

I wrote a small Node.js API wrapper library (type=module) with several exported methods that all use the same fetcher method internally for actually calling the API. Currently the fetcher method takes URL host and basic auth username and password from the process.env variables, so any project that uses the library has to define these env variables somehow.

However, this setup has the limitation that you can only work on one environment at a time. Now I want to write a Node.js application that connects to both dev and prod environments so I need a way to config these three parameters before calling the methods. I wanted to write a class that takes these as parameters (so as state) from which the same API wrapper methods are available but obviously the fetcher should then use these values instead of the environment loaded variables. So I'm looking for a way for the fetcher method to access this info without having to pass them through every API method as extra parameters (which would also change/break the signature for the "default use case").

Anyone knows how to deal with this?

about 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda