Monday, 13 March 2017

Export functions Nodejs

I'm using module.exports to export list of module. Below is my Models/Message.js

var msgModel = function()
{
    var getMsg = function() {
        return "Hello World";
    }
    return{
        getMsg : getMsg
    }
}
module.exports =  msgModel;

Below is my app.js

var msgModel = require('./Models/Message');
console.log(msgModel.getMsg());

It raised me error

console.log(msgModel.getMsg());
                 ^

I can't figure out the problem.



via nvtthang

No comments:

Post a Comment