0
0
Expressframework~5 mins

res.send for general responses in Express - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does res.send() do in Express?

res.send() sends a response back to the client. It can send strings, objects, or buffers as the HTTP response body.

Click to reveal answer
beginner
Can res.send() send JSON objects directly?

Yes, if you pass an object to res.send(), Express converts it to JSON and sets the Content-Type header to application/json.

Click to reveal answer
intermediate
What happens if you call res.send() multiple times in one request?

Only the first call to res.send() sends the response. Subsequent calls are ignored or cause errors because the response is already sent.

Click to reveal answer
intermediate
How does res.send() differ from res.json()?

res.send() can send any type of response (string, buffer, object), while res.json() specifically sends JSON and sets the Content-Type header to application/json.

Click to reveal answer
beginner
What is a simple example of using res.send() to send a text response?
app.get('/hello', (req, res) => {
  res.send('Hello, friend!');
});

This sends the text 'Hello, friend!' to the browser.

Click to reveal answer
What type of data can res.send() send in Express?
AOnly HTML files
BOnly strings
COnly JSON objects
DStrings, objects, buffers
If you pass an object to res.send(), what does Express do?
AConverts it to JSON and sets Content-Type to application/json
BThrows an error
CSends it as plain text
DIgnores the object and sends nothing
What happens if you call res.send() twice in the same route handler?
ABoth responses are sent one after another
BThe second call overwrites the first response
COnly the first call sends a response; the second is ignored or causes an error
DExpress queues both responses and sends them together
Which method is more specific for sending JSON responses?
Ares.render()
Bres.json()
Cres.send()
Dres.redirect()
What header does Express set automatically when sending an object with res.send()?
AContent-Type: application/json
BContent-Type: text/html
CContent-Type: text/plain
DContent-Type: application/xml
Explain how res.send() works in Express and what types of data it can send.
Think about what happens when you pass different data types to res.send()
You got /4 concepts.
    Describe the difference between res.send() and res.json() in Express.
    Consider when you want to send JSON specifically versus other data
    You got /4 concepts.