January 2018
Beginner
658 pages
13h 10m
English
Now we haven't talked about how to set a custom status for our response, but we can do that with one method, .status. Let's add .status in server.js, chaining it on, before, send('Hello world!'), just like this:
app.get('/', (req, res) => { res.status().send('Hello world!');});
Then, we can pass in the numerical status code. For example, we could use a 404 for page not found:
app.get('/', (req, res) => { res.status(404).send('Hello world!');});
If we save the file this time around, the body is going to match up, but inside the Terminal we can see we now have a different error:

We expected a 200, but we got a 404. Using ...
Read now
Unlock full access