0
I’m new to Node JS + Mongodb and I’ve had a doubt for a couple of days that I couldn’t figure out how to solve it.
My problem is this:
I have a file of routes that make a call to a model, as in the example below:
Route archive:
'use strict';
module.exports = function(app) {
app.get('/api/hotels/', function(req, res) {
let hotels = new app.model.Hotels();
hotels.pageList(req.params.page, req.params.qtd, (err, docs) => {
res.status(404).json({
msg: 'implementation not found'
})
})
})
}
Model archive:
'use strict';
function Hotels() {
this._hotels = process.db.get().collection('hotels')
this._ObjectID = process.db.ObjectID()
}
Hotels.prototype.pageList = function(page, qtd, cb) {
//list all hotels
this._hotels.find(function(err, hotels) {
if (err) {
return err;
} else {
return hotels;
}
})
cb()
}
module.exports = function() {
return Hotels
}
The problem is that I don’t know how to return the model result to the route and display JSON object in the user’s browser.
Someone could give me a light?