Export And Require Module
NodeJS
Medium
3 views
Problem Description
Create a small math module and use it to add two numbers.
Output Format
Print one line.
Constraints
Show module.exports usage (single file demo).
Official Solution
const math = { add(a, b) { return a + b; } };
function requireLike(mod) {
return mod;
}
const m = requireLike(math);
console.log('Sum: ' + m.add(3, 4));
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!