I have the following in a module file:
module.exports = { myfunc: myfunc }; var myfunc = function(callback){ callback(err,reply); };
In an other file I got the reference to that module
var mymodule = require('./modules/mymodule'); mymodule.myfunc(function(err, reply){ ... });
When I call the mymodule.myfunc() I get an error saying "property 'myfunc' is not a function". This happens only with exported functions. The same module exports some 'string' fields and these are working just fine.
When you assign module.exports
, the myfunc
function is still undefined. Try to assign it after declaring it:
var myfunc = function(callback){ callback(err,reply); }; module.exports = { myfunc: myfunc };
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With