Node.js · Junior · Question 12 of 75
How do you export a function in CommonJS?
function add(a, b) {
return a + b;
}- 1
exports(add); - 2
export default add; - ✓Correct answer:
module.exports = { add };
Explanation
module.exports is the value that require() returns. export default is ES module syntax. You can also write exports.add = add, but not exports = { add }.