You're right that db.js
shouldn't call res
or even know about it. It's good to keep it separated.
Following this (untested):
db.js
var getUsersByCity = function(city, cb) {
db.users.find({'city': city}).toArray(cb);
}
server.js
app.post("/get_users_list", function(req, res) {
var body = req.body;
db.getUsersByCity(body.city, function(err, data){
if (err) {
console.log(err);
return res(err);
} else {
console.log(data);
return res.json(data);
}
});
});