0
0
Node.jsframework~10 mins

Response methods and status codes 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 200 OK status with a JSON message.

Node.js
res.status([1]).json({ message: 'Success' });
Drag options to blanks, or click blank then click option'
A500
B404
C301
D200
Attempts:
3 left
💡 Hint
Common Mistakes
Using 404 or 500 which indicate errors instead of success.
Forgetting to set the status code before sending JSON.
2fill in blank
medium

Complete the code to send a 404 Not Found status with a plain text message.

Node.js
res.status([1]).send('Page not found');
Drag options to blanks, or click blank then click option'
A500
B200
C404
D403
Attempts:
3 left
💡 Hint
Common Mistakes
Using 200 which means success instead of 404.
Using json() instead of send() for plain text.
3fill in blank
hard

Fix the error in the code to correctly send a 201 Created status with JSON data.

Node.js
res.[1](201).json({ id: 123, message: 'Created' });
Drag options to blanks, or click blank then click option'
Astatus
Bsend
Cjson
Dwrite
Attempts:
3 left
💡 Hint
Common Mistakes
Using send() instead of status() to set status code.
Not chaining json() after status().
4fill in blank
hard

Fill both blanks to send a 500 Internal Server Error with a JSON error message.

Node.js
res.[1]([2]).json({ error: 'Server error' });
Drag options to blanks, or click blank then click option'
Astatus
Bsend
C500
D404
Attempts:
3 left
💡 Hint
Common Mistakes
Using send instead of status to set status code.
Using 404 instead of 500 for server errors.
5fill in blank
hard

Fill all three blanks to send a 302 redirect to '/login' with a plain text message.

Node.js
res.[1]([2]).[3]('Redirecting to login');
Drag options to blanks, or click blank then click option'
Astatus
B302
Csend
Djson
Attempts:
3 left
💡 Hint
Common Mistakes
Using json() instead of send() for plain text.
Using wrong status code like 200 or 404.