Skip to content
Related Articles

Related Articles

How to export promises from one module to another module node.js ?

View Discussion
Improve Article
Save Article
  • Last Updated : 26 May, 2021

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.


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


// Importing check function
const promise = require("./FirstModule.js")
// Promise handling
promise.check(8).then((msg) => {
}).catch((msg) => {

Run SecondModule.js file using the below command:

node SecondModule.js


The number is even
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!