mongoose and node express code example
Example 1: mongoose and express get requests
app.get('/api/all', (req,res) =>{
Model.find({})
.then(model=> {
res.json(model)
}).catch(error=>{
res.json(error)
}
})
})
Example 2: node js + mongoose
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
// we're connected!
});