Node.js · Junior · Question 13 of 75

Why does exports = { add } not export anything in CommonJS?

Explanation

exports starts as a reference to module.exports. Adding properties (exports.add = add) works, but assigning a new object breaks the link. Use module.exports = { add } instead.

Further reading

Problem with a question

Node.js · Junior · question 13

Test yourself

Take the Node.js · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz