What is the purpose of Node.js module.exports and how do you use it?
Asked 07 September, 2021
Viewed 2.4K times
  • 60
Votes

What is the purpose of Node.js module.exports and how do you use it?

I can't seem to find any information on this, but it appears to be a rather important part of Node.js as I often see it in source code.

According to the Node.js documentation:


module

A reference to the current module. In particular module.exports is the same as the exports object. See src/node.js for more information.

But this doesn't really help.

What exactly does module.exports do, and what would a simple example be?

12 Answer