Are node modules run when they are required?
For example: You have a file foo.js that contains some code and some exports.
When I import the file by running the
Before exporting the content that are visible outside of your module, if there is same code that can be execute it it execute but the content that are export like a class will be execute in the code that import it.
For example, if I have this code
console.log("foo.js")
module.exports = {
Person: function(){}
}
the console.log
will be execute when you require
it.