07 / 07

List all response methods?

Difficulty: 5/10
response methods, status handling, content negotiation
  1. 1

    res.download(): Prompt a file to be downloaded.

  2. 2

    res.end(): End the response process.

  3. 3

    res.json(): Send a JSON response.

  4. 4

    res.jsonp(): Send a JSON response with JSONP support.

  5. 5

    res.redirect(): Redirect a request.

  6. 6

    res.render(): Render a view template.

  7. 7

    res.send(): Send a response of various types.

  8. 8

    res.sendFile(): Send a file as an octet stream.

  9. 9

    res.sendStatus(): Set the response status code and send its string representation as the response body.

Scenario Questions

0-2 years experience

  1. 1You need to return a JSON object after reading a user record from the database. Which Express response method would you use and why?
  2. 2If a route handler calls `res.send('OK')` and then later calls `res.json({status:'ok'})`, what will the client receive?

2-5 years experience

  1. 1Your team added an endpoint that should redirect unauthenticated users to the login page while preserving the original URL. Which response method would you pick and how would you implement it?
  2. 2A file‑download route sometimes returns a 500 error instead of the file. Which response method is best for sending files, and what common mistakes could cause the failure?
  3. 3You need to send a 403 status with a plain‑text error message in one line. Which Express methods would you chain, and why might `res.sendStatus(403)` be insufficient?

5-8 years experience

  1. 1Our API contract requires every response to have a `{code, message, data}` envelope. How would you enforce this across many routes without duplicating code, and which response methods would you use inside that solution?
  2. 2A route streams large CSV files and is causing high memory usage. Discuss how you would change the response handling, comparing `res.sendFile`, `res.download`, and manual streaming with `res.write`/`res.end`.

8+ years experience

  1. 1The organization is migrating legacy Express services that use `res.send` everywhere to a new standard that separates status handling, payload formatting, and error handling. Describe the architectural changes you’d propose, including any middleware or response‑wrapper patterns.
  2. 2When building a micro‑services platform, how would you standardize response handling to support versioning, content negotiation, and observability? Compare using `res.json` directly versus a custom serializer layer.

Follow-up Questions

  • What happens if you call another response method after one has already sent a response?
  • How would you set a custom header before sending JSON data?
  • Why might you choose res.sendStatus over res.status(...).send(...) in a simple error case?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.