1
0

Video 92: Resource Reading Endpoints: Part II

This commit is contained in:
JayWll 2020-02-23 15:33:15 -07:00
parent ff4ec82ef5
commit b4f47db7ab

View File

@ -50,6 +50,28 @@ app.post('/tasks', (req, res) => {
}) })
}) })
app.get('/tasks', (req, res) => {
Task.find({}).then((tasks) => {
res.send(tasks)
}).catch((e) => {
res.status(500).send()
})
})
app.get('/tasks/:id', (req, res) => {
const _id = req.params.id
Task.findById(_id).then((task) => {
if (!task) {
return res.status(404).send()
}
res.send(task)
}).catch((e) => {
res.status(500).send()
})
})
app.listen(port, () => { app.listen(port, () => {
console.log('Server is up on port ' + port) console.log('Server is up on port ' + port)
}) })