0
0
Expressframework~10 mins

Method chaining on response in Express - 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 JSON response with status 200.

Express
res.status(200).[1]({ message: 'Success' });
Drag options to blanks, or click blank then click option'
Ajson
Bend
Csend
Dwrite
Attempts:
3 left
💡 Hint
Common Mistakes
Using send instead of json causes the response to be sent as plain text.
Using end does not send JSON data.
2fill in blank
medium

Complete the code to set a header and send a plain text response.

Express
res.set('Content-Type', 'text/plain').[1]('Hello World');
Drag options to blanks, or click blank then click option'
Ajson
Bend
Cwrite
Dsend
Attempts:
3 left
💡 Hint
Common Mistakes
Using json sends JSON format, not plain text.
Using end does not allow chaining after setting headers.
3fill in blank
hard

Fix the error in chaining to set status and send a response.

Express
res.[1](404).send('Not Found');
Drag options to blanks, or click blank then click option'
Astatus
BsendStatus
CsetStatus
DwriteStatus
Attempts:
3 left
💡 Hint
Common Mistakes
Using sendStatus ends the response and chaining send after causes error.
Using setStatus or writeStatus are not valid Express methods.
4fill in blank
hard

Fill both blanks to set a cookie and send a JSON response.

Express
res.[1]('token', 'abc123').[2]({ success: true });
Drag options to blanks, or click blank then click option'
Acookie
Bjson
Csend
DsetHeader
Attempts:
3 left
💡 Hint
Common Mistakes
Using setHeader instead of cookie does not set cookies properly.
Using send instead of json sends plain text, not JSON.
5fill in blank
hard

Fill all three blanks to set status, header, and send a plain text response.

Express
res.[1](201).[2]('X-Custom', '123').[3]('Created');
Drag options to blanks, or click blank then click option'
Astatus
Bset
Csend
Djson
Attempts:
3 left
💡 Hint
Common Mistakes
Using json instead of send sends JSON, not plain text.
Using setHeader instead of set is not the Express method.