NodeJS: module.exports property is not a function

javascript, node.js

Solution

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
};

Problem

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.

Original source