I'm requiring a lot of exports from a module as follows:
employee.js
// Some logic goes here
module.exports = {
AvgEmployees,
AvgDailyEmployee,
AvgAbsenceEmployee,
AvgWorkDaysEmpolyee,
...
..
..
};
main.js
const {
AvgEmployees,
AvgDailyEmployee,
AvgAbsenceEmployee,
AvgWorkDaysEmployee,
...
...
...
} = require('src/employee.js');
// Do what's needed with all the imports
// ....
// ...
I'm importing more than 50 imports and it starts to bother me every time to name all the imports.
Is it possible to import all of them at once without naming each one specifically ?
Yes, like this:
const employee = require('src/employee.js');
// Do what's needed with all the imports
employee.AvgEmployees
employee.AvgDailyEmployee
// ....
// ...
Variable employee is the value of module.exports and const { ... } = require('src/employee.js'); is just object destructuring: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment