Ali Ali - 1 year ago 176
Node.js Question

Declare multiple module.exports in Node.js

What I'm trying to achieve is to create one module that contains multiple functions in it.


module.exports = function(firstParam) { console.log("You did it"); },
module.exports = function(secondParam) { console.log("Yes you did it"); },
// This may contain more functions


var foo = require('module.js')(firstParam);
var bar = require('module.js')(secondParam);

The problem I have is that the
is an object type and the
is a URL string, but when I have that it always complains that the type is wrong.

How can I declare multiple module.exports in this case?

Answer Source

You can do something like:

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

Or even just:

exports.method = function() {};
exports.otherMethod = function() {};
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download