I have a default Express app, and my routes index.js file looks like this:
var user = require('../models/user');
exports.index = function(req, res){
res.render('index', { title: 'Express', object: obj });
};
Now, suppose in my app.js file the client
object that is the redis client connected to my redis-server, and I would like to be able to use that client object in my user model, for example to avoid repeated login attempts. How can I be able to access that object in my user model? Here is the code for that model
var mongoose = require('mongoose');
var userSchema = mongoose.Schema({
email: { type: String, required: true, index: { unique: true } },
password: { type: String, required: true },
name: { type: String, required: true }
});
var User = mongoose.model('User', userSchema);
exports.canLogin = function(mIn, pIn, next){
User.findOne({
email: mIn
}, function(err, user){
if(!err){
if(user.password == pIn)
next(true);
else next(false);
} else next(false);
});
};