How to export promises from one module to another module node.js ? Last Updated : 26 May, 2021 Comments Improve Suggest changes Like Article Like Report JavaScript is an asynchronous single-threaded programming language. Asynchronous means multiple processes are handled at the same time. Callback functions vary for the asynchronous nature of the JavaScript language. A callback is a function that is called when a task is completed, thus helps in preventing any kind of blocking and a callback function allows other code to run in the meantime, but the main problem with the callback function is the callback hell problem. The solution of callback hell is using the promises in this article we will discuss how to export from one module to another module. Project Structure: It will look like this. FirstModule.js function check(number) { return new Promise((Resolve, reject) => { if (number % 2 == 0) { Resolve("The number is even") } else { reject("The number is odd") } }) } // Exporting check function module.exports = { check: check }; SecondModule.js // Importing check function const promise = require("./FirstModule.js") // Promise handling promise.check(8).then((msg) => { console.log(msg) }).catch((msg) => { console.log(msg) }) Run SecondModule.js file using the below command: node SecondModule.jsOutput: The number is even Comment More infoAdvertise with us Next Article How to export promises from one module to another module node.js ? Z zack_aayush Follow Improve Article Tags : Web Technologies Node.js Node.js-Methods NodeJS-Questions Similar Reads What is the purpose of module.exports in node.js ? The module.exports is actually a property of the module object in node.js. module. Exports is the object that is returned to the require() call. By module.exports, we can export functions, objects, and their references from one file and can use them in other files by importing them by require() meth 3 min read How to write code using module.exports in Node.js ? module is a discrete program, contained in a single file in Node.js. They are tied to files with one module per file. module.exports is an object that the current module returns when it is "required" in another program or module. We are going to see a simple code like the calculator to learn how to 3 min read How to resolve a "Cannot find module" error using Node.js? This article outlines the steps you can take to troubleshoot and fix "Cannot find module" errors in your Node.js projects. These errors typically arise when Node.js cannot locate a module you're trying to use in your code. Table of Content Error "Cannot find module" Approach to Solve the ErrorInstal 3 min read How to operate callback-based fs.mkdir() method with promises in Node.js ? The fs.mkdir() method is defined in the File System module of Node.js. The File System module is basically to interact with the hard disk of the user's computer. The mkdir() method is used to asynchronously create a directory. The fs.mkdir() method is based on callback. Using callback methods leads 4 min read How to export modules with sub-modules in ReactJS ? One of the key features of React is its modular structure, which allows developers to break down their code into reusable components. In many cases, these components are organized into modules and submodules, which can be exported and imported into other parts of the application. Prerequisites:NPM 3 min read Like