thelonglqd
thelonglqd

Reputation: 1862

Assign value to exports in Node.js

For emxaple in these line of code below:

const fs = require('fs')

We get the object in module.export, not the object in exports of fs module.

But inside Express code, I see some assignment to exports like below, I do not know the purpose of it and this is my question

exports.application = proto;
exports.request = req;
exports.response = res;

Please help to let me know if you have any ideas about this.

Upvotes: 0

Views: 138

Answers (1)

Sello Mkantjwa
Sello Mkantjwa

Reputation: 1915

exports and module.exports refer to the same thing (exports is a reference to module.exports), unless you reassign exports by doing exports=foo. Nodejs always exports module.exports so as long as you do not reassign exports to something else, exports.bar=foo and module.exports.bar=foo have the same effect.

Upvotes: 2

Related Questions