Bird
Raised Fist0
Expressframework~20 mins

res.send for general responses in Express - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Express res.send Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
What does this Express code send to the client?
Consider this Express route handler:
app.get('/hello', (req, res) => { res.send('Hello World!'); });

What will the client receive when requesting /hello?
Express
app.get('/hello', (req, res) => { res.send('Hello World!'); });
AA redirect to '/hello/world'
BThe string 'Hello World!' as the response body with status 200
CAn empty response with status 204
DA JSON object { message: 'Hello World!' }
Attempts:
2 left
💡 Hint
res.send sends the exact data you give it as the response body.
📝 Syntax
intermediate
2:00remaining
Which option correctly sends a JSON response using res.send?
You want to send this JSON object as a response:
{ success: true, data: [1, 2, 3] }

Which code correctly sends it using res.send?
Ares.send('success: true, data: [1, 2, 3]');
Bres.send(JSON.stringify({ success: true, data: [1, 2, 3] }));
Cres.send({ success: true, data: [1, 2, 3] });
Dres.send({ 'success': 'true', 'data': '[1, 2, 3]' });
Attempts:
2 left
💡 Hint
res.send can accept an object and automatically sends JSON.
🔧 Debug
advanced
2:00remaining
Why does this code cause an error?
Look at this Express handler:
app.get('/test', (req, res) => { res.send(123); res.send('Done'); });

What error or behavior will happen when a client requests /test?
Express
app.get('/test', (req, res) => { res.send(123); res.send('Done'); });
AError: Cannot set headers after they are sent to the client
BThe client receives '123Done' as a combined response
CThe client receives only 'Done' as the response
DThe server crashes with a syntax error
Attempts:
2 left
💡 Hint
You can only send one response per request.
❓ state_output
advanced
2:00remaining
What is the Content-Type header when sending a number with res.send?
Given this code:
app.get('/number', (req, res) => { res.send(42); });

What Content-Type header will the client receive?
Express
app.get('/number', (req, res) => { res.send(42); });
ANo Content-Type header is sent
Bapplication/json; charset=utf-8
Ctext/plain; charset=utf-8
Dtext/html; charset=utf-8
Attempts:
2 left
💡 Hint
Numbers are converted to strings when sent.
🧠 Conceptual
expert
2:00remaining
Which statement about res.send behavior is true?
Choose the correct statement about how res.send works in Express:
Ares.send ends the response process and cannot be called multiple times per request
Bres.send buffers the entire response before sending it to the client
Cres.send automatically sets Content-Type to application/json when sending objects
Dres.send can only send strings and buffers, not objects or numbers
Attempts:
2 left
💡 Hint
Think about what happens after res.send is called.

Practice

(1/5)
1. What does res.send() do in an Express app?
easy
A. Logs information to the console
B. Sends a response back to the client and ends the request
C. Reads data from the client request
D. Starts a new server

Solution

  1. Step 1: Understand the purpose of res.send()

    res.send() is used to send a response back to the client in Express.
  2. Step 2: Recognize that it ends the response

    After sending data, res.send() automatically ends the response, so no more data is sent.
  3. Final Answer:

    Sends a response back to the client and ends the request -> Option B
  4. Quick Check:

    res.send() = sends response [OK]
Hint: Remember: res.send sends and finishes response [OK]
Common Mistakes:
  • Thinking res.send starts the server
  • Confusing res.send with reading request data
  • Assuming res.send logs to console
2. Which of the following is the correct syntax to send a plain text response using res.send?
easy
A. res.send('Hello');
B. res.send[Hello];
C. res.send({ message: 'Hello' });
D. res.send = 'Hello';

Solution

  1. Step 1: Identify correct method call syntax

    The correct way to call res.send is as a function with parentheses and the data inside.
  2. Step 2: Check the options for valid syntax

    res.send('Hello'); uses res.send('Hello'); which is correct. res.send({ message: 'Hello' }); sends an object, which is valid but not plain text. Options B and D have invalid syntax.
  3. Final Answer:

    res.send('Hello'); -> Option A
  4. Quick Check:

    Correct function call = res.send('text') [OK]
Hint: Use parentheses and quotes: res.send('text') [OK]
Common Mistakes:
  • Using square brackets instead of parentheses
  • Assigning value instead of calling function
  • Sending object when plain text is needed
3. What will the client receive when this Express route runs?
app.get('/test', (req, res) => {
  res.send({ success: true });
});
medium
A. A plain text: '[object Object]'
B. Nothing, response is empty
C. An error because object can't be sent
D. A JSON string: '{"success":true}'

Solution

  1. Step 1: Understand res.send with an object

    When res.send() receives an object, Express converts it to JSON automatically.
  2. Step 2: Predict the client response

    The client will get a JSON string representing the object: '{"success":true}'.
  3. Final Answer:

    A JSON string: '{"success":true}' -> Option D
  4. Quick Check:

    res.send(object) = JSON string [OK]
Hint: Objects sent with res.send become JSON strings [OK]
Common Mistakes:
  • Expecting plain text '[object Object]'
  • Thinking it causes an error
  • Assuming empty response
4. Identify the error in this Express route:
app.get('/hello', (req, res) => {
  res.send('Hello');
  res.send('Again');
});
medium
A. Calling res.send twice causes an error
B. Missing semicolon after res.send
C. res.send cannot send strings
D. Route path is invalid

Solution

  1. Step 1: Check multiple res.send calls in one route

    Once res.send() is called, the response is finished and cannot be sent again.
  2. Step 2: Understand the error caused

    Calling res.send() a second time causes an error because the response is already closed.
  3. Final Answer:

    Calling res.send twice causes an error -> Option A
  4. Quick Check:

    Only one res.send per response [OK]
Hint: Send response once; multiple res.send calls cause errors [OK]
Common Mistakes:
  • Ignoring that response ends after first send
  • Thinking multiple sends append data
  • Blaming syntax or route path
5. You want to send a JSON response with a status code 201 and a message 'Created' using res.send. Which code correctly does this?
hard
A. res.send({ status: 201, message: 'Created' });
B. res.send(201, { message: 'Created' });
C. res.status(201).send({ message: 'Created' });
D. res.status(201).send('Created');

Solution

  1. Step 1: Set status code before sending response

    Use res.status(201) to set the HTTP status code to 201.
  2. Step 2: Send JSON object with message

    Chain .send({ message: 'Created' }) to send the JSON response.
  3. Final Answer:

    res.status(201).send({ message: 'Created' }); -> Option C
  4. Quick Check:

    Status then send JSON = res.status(201).send({ message: 'Created' }); [OK]
Hint: Chain res.status(code).send(data) to set status and send [OK]
Common Mistakes:
  • Passing status code as first argument to send
  • Sending status inside JSON instead of HTTP status
  • Sending plain text when JSON is needed
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard