app.get('/test', (req, res) => { res.status(201).type('text/plain').send('Success'); });
The status(201) sets the HTTP status code to 201. The type('text/plain') sets the Content-Type header to plain text. Finally, send('Success') sends the string as the response body. So the client gets status 201, plain text content type, and body 'Success'.
Method chaining requires setting the status before sending the response. res.status(404).json(...) correctly sets status 404 and sends JSON. Option D tries to set status after sending, which won't work. Option D uses send which sends JSON but chaining status after send is invalid. Option D uses a non-existent method sendJson.
app.get('/error', (req, res) => { res.send('First response').status(200); });
Calling res.send() sends the response immediately, including headers. Trying to set status after sending has no effect or may cause an error because headers are already sent. The correct order is to set status first, then send.
app.get('/chain', (req, res) => { res.status(202).status(204).send('Done'); });
Calling res.status(202) sets status to 202, but then res.status(204) overwrites it to 204. The last status call before send determines the final status code.
Once res.send() is called, the response is sent and closed. Any further method calls on res do not affect the response. You cannot send multiple responses for one request. res.status() must be called before res.send(). Both res.status() and res.json() return the response object, so chaining is possible.