0

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.

thelonglqd
  • 1,805
  • 16
  • 28
  • 1
    Possible duplicate of [Difference between "module.exports" and "exports" in the CommonJs Module System](https://stackoverflow.com/questions/16383795/difference-between-module-exports-and-exports-in-the-commonjs-module-system) – OscarRyz Oct 02 '17 at 02:59
  • If this is `req` and `res` from a particular http request, then this code is probably wrong or at best a very bad design. You would have to show us a lot more context for us to help you further. – jfriend00 Oct 02 '17 at 03:08
  • I just want to focus on assignment to export purpose, I can thing the request and response in the code is “whatever”. – thelonglqd Oct 02 '17 at 03:34

1 Answers1

2

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.

Sello Mkantjwa
  • 1,798
  • 1
  • 20
  • 36