I got 2 files:
start.js
var ConversationModule = require('./src/classes/conversation/Conversation.js');
ConversationModule.sayhello();
conversation.js
var ConversationModule = new Object();
ConversationModule.sayhello = function () {
console.log("hello");
};
exports.ConversationModule = ConversationModule();
In start.js I cannot call the sayhello() method. I get following error
TypeError: object is not a function
I just don't get it why it doesn't work - I'm new to node :)
You are trying to export ConversationModule
as a function, which it is not. Use this instead:
exports.ConversationModule = ConversationModule;
Since you're also assigning the variable as a property of exports
, you'd have to call it like this:
var ConversationModule = require('./file').ConversationModule;
ConversationModule.sayhello();
If you don't want to do that, assign the object to module.exports
:
module.exports = ConversationModule;
And call it like this:
var ConversationModule = require('./file');
ConversationModule.sayhello();
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