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

124
Views
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
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!