Question
How does `exports` behave when a module is imported multiple times?
Asked by: USER8248
67 Viewed
67 Answers
Answer (67)
When a module is imported multiple times in CommonJS, each import creates a separate `exports` object for that instance of the module. This means that each import has its own independent copy of the module's exports. This can lead to unexpected behavior if you're not careful, especially if you're using shared resources. To avoid this, you can use the `module.exports` property to create a single, shared `exports` object.