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

128
Views
module.exports not returning a value

My module file is not returning anything to the main file.

Does it have to do with callbacks?

login.js:

// ...
async function request(url) {
    return await axios.post(url).then(res => {return res})
}

function accessToken() {
  var url = generateRequestURL()
  var response = request(url)
  response.then(function(result) {
      var responseData = result.data
      var parsed = parser.parse(responseData)
      var error = 'Could not generate access token.'
      
      var isError = parsed[0].attributes.errorMessage
      if (isError) {
        return error
      } else {
        var tokenGenerated = parser.parse(parsed[0].innerXML)
        var token = tokenGenerated[0].attributes.accessToken
        return token
      }
  })
}

module.exports = accessToken

index.js:

const token = require('./login.js')
const accessToken = token()

console.log(accessToken) // this returns undefined

Any help is appreciated!

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!