Declare multiple module.exports in Node.js

You can do something like:

module.exports = {
    method: function() {},
    otherMethod: function() {},
};

Or just:

exports.method = function() {};
exports.otherMethod = function() {};

Then in the calling script:

const myModule = require('./myModule.js');
const method = myModule.method;
const otherMethod = myModule.otherMethod;
// OR:
const {method, otherMethod} = require('./myModule.js');

To export multiple functions you can just list them like this:

module.exports = {
   function1,
   function2,
   function3
}

And then to access them in another file:

var myFunctions = require("./lib/file.js")

And then you can call each function by calling:

myFunctions.function1
myFunctions.function2
myFunctions.function3

Tags:

Module

Node.Js