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

126
Vistas
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 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