January 2018
Beginner
658 pages
13h 10m
English
There will be two sides to this express route, the actual setup in server.js and the test. We can start inside server.js. In here, we'll make a new route. First, let's add a few comments to specify exactly what we'll do. It's going to be an HTTP GET route. The route itself will be /users and we can just assume this returns an array of users:
app.get('/', (req, res) => { res.status(404).send({ error: 'Page not found.', name: 'Todo App v1.0' });}); // GET /users
We can pass an array back through the send method, just like we do an object in the previous code. Now this array is going to be an array of objects where each object is a user. For now, we want to give users a name property and an age prop:
// GET /users ...
Read now
Unlock full access