Complete the code to send a 200 OK status with a JSON message.
res.status([1]).json({ message: 'Success' });
The status(200) sets the HTTP status code to 200, which means OK. Then json() sends the JSON response.
Complete the code to send a 404 Not Found status with a plain text message.
res.status([1]).send('Page not found');
json() instead of send() for plain text.The status(404) sets the HTTP status code to 404, meaning the requested resource was not found.
Fix the error in the code to correctly send a 201 Created status with JSON data.
res.[1](201).json({ id: 123, message: 'Created' });
send() instead of status() to set status code.json() after status().The status() method sets the HTTP status code. Then json() sends the JSON response. Using send() or write() alone won't set the status code properly.
Fill both blanks to send a 500 Internal Server Error with a JSON error message.
res.[1]([2]).json({ error: 'Server error' });
send instead of status to set status code.Use status(500) to set the HTTP status code to Internal Server Error, then send JSON with json().
Fill all three blanks to send a 302 redirect to '/login' with a plain text message.
res.[1]([2]).[3]('Redirecting to login');
json() instead of send() for plain text.Use status(302) to set the redirect status, then send() to send the plain text message.