Declare multiple module.exports in Node.js -
what i'm trying achieve create 1 module contains multiple functions in it.
module.js:
module.exports = function(firstparam) { console.log("you did it"); }, module.exports = function(secondparam) { console.log("yes did it"); }, // may contain more functions
main.js:
var foo = require('module.js')(firstparam); var bar = require('module.js')(secondparam);
the problem have firstparam
object type , secondparam
url string, when have complains type wrong.
how can declare multiple module.exports in case?
you can like:
module.exports = { method: function() {}, othermethod: function() {} }
or just:
exports.method = function() {}; exports.othermethod = function() {};
then in calling program:
var mymethods = require('./mymodule.js'); var method = mymethods.method; var othermethod = mymethods.othermethod;
Comments
Post a Comment