Expose Functionality from a Node.js file using exports Last Updated : 14 Oct, 2021 Comments Improve Suggest changes Like Article Like Report Module.exports API to expose Data to other files Node supports built-in module system. Node.js can import functionality which are exposed by other Node.js files. To import something, you need to use the import functionality exposed by the library.js file that is present in the current file folder. const library = require('./library') // Path The functionality in the file must be exposed before it could be imported into any other files. An object defined in the file by default is private and unexposed to the outer world. The module.exports file API is offered by the module system to implement in the code. module is a variable that represents the current module and exports is an object which will be exposed as a module. So, the module.exports and exports will both be exposed as a module. module.exports is basically an object which returns the result of a require call. You need the new exports property to import the object or function in any other parts of your app. You can do so in 2 ways: The first way is to assign an object to module.exports where the object is provided out of the box by module system. Examples: javascript const person = { firstName: 'John', lastName: 'Smith' } module.exports = Person // in the file where you want to export const person= require(‘./person) The second way is by adding the exported object as a property of exports. You can use exports to export multiple objects, function or data: javascript const Person = { firstName: 'John', lastName: 'Smith' } exports.person = person Or Directly javascript exports.person = { firstName: 'John', lastName: 'Smith' } You'll use it by referencing a property of your import in the other file: javascript Const items = require('items') items.person Or javascript const person= require('./items').person What's the difference between module.exports and exports? The first exposes the object it points to whereas the latter exposes the properties of the object it points to. Comment More infoAdvertise with us Next Article Expose Functionality from a Node.js file using exports M mayank021 Follow Improve Article Tags : Algorithms DSA Practice Tags : Algorithms Similar Reads How to export multiple values or elements in a Module ? In Node.js, modules are an essential part of the architecture, allowing you to organize code into separate files and reuse it across different parts of your application. One common requirement is to export multiple values or elements from a module so that they can be imported and used in other parts 4 min read How to Import all Exports of a File as an Object in Node.js ? In Node.js, you can import all exports of a file as an object using the ES Modules syntax (import) or the CommonJS syntax (require). This approach is useful when you have multiple exports from a module and want to access them conveniently through a single object interface. Below are the approaches t 4 min read How to work with Node.js and JSON file ? Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. With node.js as backend, the developer can maintain a single codebase for an entire application in javaScript.JSON on the other hand, stands for JavaScript Object Notation. It is a lightweight format for storing and exchanging d 4 min read How to share code between Node.js and the browser? In this article, we will explore how to write JavaScript modules that can be used by both the client-side and the server-side applications.We have a small web application with a JavaScript client (running in the browser) and a Node.js server communicating with it. And we have a function getFrequency 3 min read Node Export Module In NodeJS, module.exports is used to share functions, objects, or values from one file to the other file so that other files can use them. This is an essential part of organizing and reusing code across different parts of your application, making it easier to manage and maintain.Hereâs how exporting 5 min read Like