Skip to main content

What is the purpose of module.exports?

Published 1 min readMarkdown
Part of seriesNode
What is the purpose of module.exports?

module.exports is the object that's returned as the result of a require call. You can use it to export a single value or a list of values. It helps in achieving modular programming.

// Define a value.
const myValue = 'Hello, World!';

// Export the value.
module.exports = myValue;

Then, in another file, you can use require to access that value:

// Load the value.
const myValue = require('./path/to/my/module');

console.log(myValue);  // Outputs: "Hello, World!"

About the author

  • Full Stack Developer with a passion for building web applications. PHP, Node.js, Laravel, MySQL, MongoDB. Love collaborating & making a difference

No comments yet. Be the first to comment.

More from this blog