Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to send a 404 status code response in Express.
Node.js
res.status([1]).send('Not Found');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 200 means success, not an error.
Using 500 means server error, not resource missing.
✗ Incorrect
404 is the standard status code for 'Not Found'.
2fill in blank
mediumComplete the code to send a JSON response with status 201 for resource creation.
Node.js
res.status([1]).json({ message: 'Created' });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 400 means bad request, not creation success.
Using 404 means resource not found.
✗ Incorrect
201 status code means a resource was successfully created.
3fill in blank
hardFix the error in the code to send a 500 Internal Server Error status.
Node.js
res.status([1]).send('Internal Server Error');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 400 means client error, not server error.
Using 200 means success, not error.
✗ Incorrect
500 is the correct status code for server errors.
4fill in blank
hardFill both blanks to send a 302 redirect with a Location header.
Node.js
res.status([1]).set('Location', [2]).send();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 404 status code with Location header is incorrect.
Not setting Location header causes redirect to fail.
✗ Incorrect
302 is the status code for temporary redirect. The Location header tells where to redirect.
5fill in blank
hardFill all three blanks to send a 400 Bad Request with JSON error details.
Node.js
res.status([1]).json({ error: [2], message: [3] });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 200 status means success, not error.
Not providing error details makes debugging harder.
✗ Incorrect
400 status code means bad request. The JSON provides error type and message.