Skip to content
Learn Netverks

Lesson

Step 21/36 58% through track

request-response

Request and response objects

Last reviewed May 28, 2026 Content v20260528
Track mode
nodejs_server
Means
Node sandbox
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches Request and response objects: the syntax, APIs, and habits you need before advancing in Node.js.

Teams ship Request and response objects on every Node.js codebase—skipping it leaves gaps in debugging and code reviews.

You will apply Request and response objects in contexts like: REST/GraphQL APIs, BFF layers, CLIs, webhooks, and real-time services (with WebSockets).

Run JavaScript on the Node runner when configured—never mix arbitrary shell commands in lessons.

When you can explain the previous lesson's ideas without copying starter code.

HTTP handlers read the request (method, URL, headers, body) and write the response (status, headers, body). REST APIs lean on JSON bodies and standard status codes.

Common req properties (Express)

  • req.params — route placeholders
  • req.query — query string (?page=2)
  • req.body — parsed JSON/form (after middleware)
  • req.headers — Authorization, Content-Type, etc.

Response helpers

  • res.status(404).json({ error: 'Not found' })
  • res.redirect(302, '/login')
  • res.set('Cache-Control', 'no-store')

Content negotiation

Set Content-Type accurately—application/json for APIs, text/html for pages. Wrong types break clients and caching.

Important interview questions and answers

  1. Q: params vs query?
    A: Params are path segments (/users/5); query is optional filters (?sort=name)—both need validation.
  2. Q: When send 204?
    A: Success with no body—common for DELETE operations.

Self-check

  1. Where does JSON body data appear after express.json()?
  2. Why set Content-Type for JSON responses?

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • res.json vs send?
  • Status before body?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump