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

186
Views
How can you calculate number of functions in a module when exporting/importing a custom module

Taking an instance of exporting these two functions in JS

module.js

const add = (a,b) => {
    return a+b;
};

const sub = (a,b) => {
    return a-b;
};

module.exports = {add, sub};

new.js

const {add, sub} = require('./module');

console.log(add(5,4));
console.log(sub(5,4));

Help, if I was to count how many functions am I importing on new.js file.

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

0

It would be interesting to know what you are trying to achieve as it is somewhat unusual, but it should be somewhat easy to get what you are after.

You can for example import everything from './module' as an object and then count the keys or similar in the imported object to get number of functions.

So for example:

const importedFunctions = require('./module');

console.log(Object.keys(importedFunctions).length)

Edit: I saw your reply in the comments. To extend it a bit further to call all imported functions with some values you could do something like this:

Object.values(importedFunctions).forEach((fn) => fn(5, 4))
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!