0
0
Expressframework~10 mins

res.send for general responses 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 simple text response using Express.

Express
app.get('/', (req, res) => { res.[1]('Hello World!'); });
Drag options to blanks, or click blank then click option'
Asend
Bwrite
Cjson
Drender
Attempts:
3 left
💡 Hint
Common Mistakes
Using res.write which is not a method in Express response object.
Using res.json which sends JSON, not plain text.
Using res.render which is for templates.
2fill in blank
medium

Complete the code to send a JSON response using Express.

Express
app.get('/data', (req, res) => { res.[1]({ message: 'Success' }); });
Drag options to blanks, or click blank then click option'
Aend
Bsend
Cwrite
Djson
Attempts:
3 left
💡 Hint
Common Mistakes
Using res.send with an object, which works but does not explicitly set JSON headers.
Using res.end which just ends the response without sending data.
Using res.write which is not an Express method.
3fill in blank
hard

Fix the error in sending a response with status 404 and a message.

Express
app.get('/notfound', (req, res) => { res.status(404).[1]('Page not found'); });
Drag options to blanks, or click blank then click option'
Ajson
Bsend
Cwrite
Drender
Attempts:
3 left
💡 Hint
Common Mistakes
Using res.write which is not an Express method.
Using res.render which is for templates, not plain text.
Using res.json which sends JSON, but here a simple text message is expected.
4fill in blank
hard

Fill both blanks to send a JSON response with status 201 and a message.

Express
app.post('/create', (req, res) => { res.[1](201).[2]({ success: true }); });
Drag options to blanks, or click blank then click option'
Astatus
Bsend
Cjson
Dend
Attempts:
3 left
💡 Hint
Common Mistakes
Using res.send instead of res.json for JSON data.
Using res.end which does not send data.
Not chaining methods properly.
5fill in blank
hard

Fill the blanks to send a plain text response with status 500 and a custom message.

Express
app.get('/error', (req, res) => { res.[1](500).[2]('Error: Something went wrong'); });
Drag options to blanks, or click blank then click option'
Astatus
Bsend
Cwrite
Djson
Attempts:
3 left
💡 Hint
Common Mistakes
Using res.write which is not an Express method.
Using res.json which sends JSON, not plain text.
Not chaining the status and send methods.