What is the best template to use when creating modules in Node.js that have several functions called “statically”, i.e. Do not use a keyword new. Is there an equivalent in ES6 that I am missing?
Pattern 1.
module.exports.add = (x, y) => {
return x + y;
}
module.exports.multiply = (x, y) => {
return x * y;
};
const math = require('./math.js');
console.log(math.add(2, 3));
Pattern 2.
module.exports = {
add: (x, y) => {
return x + y;
},
multiply: (x, y) => {
return x * y;
}
};
const math = require('./math.js');
console.log(math.add(2, 3));
source
share