I have one module called UserProvider that looks like this
var UserProvider = function(db) { ... }
UserProvider.prototype.createUser = function(email, password, callback) { ... }
UserProvider.prototype.findUserByEmail = function(email, callback) { ... }
...
exports.UserProvider = UserProvider;
And another module called ModelProvider that looks like this
var UserProvider = require('./user').UserProvider;
var ModelProvider = function() {
...
this.User = new UserProvider(db);
}
exports.ModelProvider = ModelProvider;
But the line this.User = new UserProvider(db); doesn't allow me to access the UserProvider object in my main module that has included the ModelProvider module.
When I try to call this:
var ModelProvider = require('./model/model').ModelProvider;
var Model = new ModelProvider();
Model.User.findUserByEmail(email, function() {...});
It gives the following error:
TypeError: Object function Model(doc, fields, skipId) {
if (!(this instanceof Model))
return new Model(doc, fields, skipId);
model.call(this, doc, fields, skipId);
} has no method 'findUserByEmail'
I'm assuming there is some JavaScript trickery that I am missing to expose this down?
Thanks!
UserProviderto theexportsobject in the model module.var model = new ModelProvider()in your main module, if you accessmodel.Userwhat do you get?Modelwhich it may be confusing with the instance you have created ofModelProvider