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

278
Views
Problem exporting module in node: functions not exported correctly

I have a module that has an index.js file and 2 different utility files with functions.

Index has:

const utl = require('./tools');
const updt = require('./update');

While both files have a version of (this is the update.js exports):

module.exports = { 
    updateResults, 
    addTeamIDsToArray, 
    updateTeamStats,
    retrieveRankings, 
    numbOfWeeksToToday }

And the tools.js exports:

   module.exports = {
    add_weeks,
    format_date,
    waitForMe, 
    chooseWinner
    }

However, when I check both constants in my index.js file, one of them is empty:

    console.log(updt)
    console.log(utl)

OUTPUT:

    {}
    {
      add_weeks: [Function: add_weeks],
      format_date: [Function: format_date],
      waitForMe: [Function: waitForMe],
      chooseWinner: [Function: chooseWinner]
    }

Why is my update file not exporting correctly?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I'm assuming you mean both files have the same module.exports ?

It's impossible to answer this question without seeing whats in the "tools" directory, as it seems to be behaving correctly; returing an object of the contents exported from the file- in this case, an empty object. (Reason: OP added details)

If it's any consolation, I think you're doing this correct overall. This leads me to wonder a few things!

  • Have you tried changing the file name?
  • Using different import methods? (ESM import x from "x" / await import("x"))
  • Create some object random object (we'll call it obj = { updateResults, addTeamIDsToArray, ...}), add all the exported items, then module.exports = obj?
  • Destructuring the import to further debug? Ex: const { updateResults } = reqiure("./tools") ?
  • Obvious but made sure the relative path "./tools" is correct?

These are just a few things to check or try out, just to check.

And last but not least, good ole' turn it off and back on again just to be sure we cover it all.

about 4 years ago · Juan Pablo Isaza Report
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!