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

168
Views
How do I organise API function calls from different files?

I am trying to automatically update a bearer key which is found in login.js and have it be used to in a new axios instance in customer.js.

I am struggling to find a way to implement the function from the login.js and use it within customer.js before a new instance is created.

Login.js

async function Login(){
const Bearerget = await axios.post("https://login.salesforce.com/services/oauth2/token", config.data)
  const Bearer = `Bearer ${Bearerget.data.access_token}`
  console.log(Bearer)
  return `${Bearer}`
}

Customer.js

const login = require("./login");

Bearer = await login.Login()

const SalesforceClient = axios.create( {
  baseURL: `url`,
  timeout: 100000,
  headers: { 
    'Content-Type': 'application/json', 
    'Authorization': Bearer
}
});

async function Customers(){
//Code 
};

Customers()

What I get from the output is:

  • Goes into the login.js
  • Begins Customer()
  • then Bearer key is printed

How do I run login.js, get the bearer key from the function, and then have it be updated in the axios instance in customer.js?

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!