In an Express app, what is the effect of calling res.status(404).send('Not Found') inside a route handler?
app.get('/item', (req, res) => { res.status(404).send('Not Found'); });
Think about what res.status() sets and what send() does.
The res.status(404) sets the HTTP status code to 404. The send('Not Found') sends the response body with that status. So the client gets a 404 status and the text 'Not Found'.
Choose the correct Express code to send a 201 status with JSON {"success": true}.
Remember the correct method to set status and send JSON.
res.status(201) sets the status code. json() sends JSON data. Option C uses both correctly.
In Express, what happens if you call res.status(500).send() without any argument?
app.get('/error', (req, res) => { res.status(500).send(); });
Check what happens when send() is called with no argument.
Calling send() without arguments sends an empty response body but keeps the status code set by res.status(500).
Consider this Express code snippet:
res.status(200).status(404).send('Oops');What status code will the client receive?
Think about method chaining and which status code is last set.
The last status(404) call overrides the previous status(200). So the response status is 404.
In REST APIs using Express, which HTTP status code should you set with res.status() when a new resource is successfully created?
Think about the standard HTTP codes for resource creation.
Status 201 means 'Created' and is the standard code to indicate successful creation of a resource.