Complete the code to send a 200 OK status response in Express.
app.get('/home', (req, res) => { res.status([1]).send('Welcome!'); });
The status code 200 means the request was successful and the server is sending the requested data.
Complete the code to send a 404 Not Found status when a resource is missing.
app.get('/item/:id', (req, res) => { const item = findItem(req.params.id); if (!item) { res.status([1]).send('Item not found'); } });
404 means the requested resource was not found on the server.
Fix the error in the code to send a 201 Created status after a new user is added.
app.post('/users', (req, res) => { addUser(req.body); res.status([1]).send('User created'); });
201 status code means a new resource was successfully created on the server.
Fill both blanks to send a 400 Bad Request status with a JSON error message.
app.post('/login', (req, res) => { if (!req.body.username) { res.status([1]).json({ error: '[2]' }); } });
400 status means the client sent a bad request. The message 'Bad Request' explains the error.
Fill all three blanks to send a 500 Internal Server Error with a JSON message and end the response.
app.get('/data', (req, res) => { try { const data = getData(); res.json(data); } catch (error) { res.status([1]).json({ message: '[2]' }).[3](); } });
500 means a server error occurred. The message explains it. Calling end() finishes the response.