0
0
Node.jsframework~10 mins

Status code usage patterns in Node.js - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A200
B500
C404
D302
Attempts:
3 left
💡 Hint
Common Mistakes
Using 200 means success, not an error.
Using 500 means server error, not resource missing.
2fill in blank
medium

Complete 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'
A400
B500
C404
D201
Attempts:
3 left
💡 Hint
Common Mistakes
Using 400 means bad request, not creation success.
Using 404 means resource not found.
3fill in blank
hard

Fix 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'
A500
B400
C200
D403
Attempts:
3 left
💡 Hint
Common Mistakes
Using 400 means client error, not server error.
Using 200 means success, not error.
4fill in blank
hard

Fill 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'
A302
B'/new-url'
C'/home'
D404
Attempts:
3 left
💡 Hint
Common Mistakes
Using 404 status code with Location header is incorrect.
Not setting Location header causes redirect to fail.
5fill in blank
hard

Fill 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'
A400
B'BadRequest'
C'Invalid input data'
D200
Attempts:
3 left
💡 Hint
Common Mistakes
Using 200 status means success, not error.
Not providing error details makes debugging harder.