Request/Response Handling in Node.js

From the Express.js cheat sheet · Request & Response · verified Jul 2026

Request/Response Handling

Work with req and res objects

javascript
// Request properties
req.params    // Route parameters
req.query     // Query string
req.body      // Request body
req.headers   // Headers
req.cookies   // Cookies
req.method    // HTTP method
req.url       // URL path
req.ip        // Client IP

// Response methods
res.send('text')
res.json({ data })
res.status(404).send('Not found')
res.redirect('/login')
res.render('template', { data })
res.sendFile('/path/to/file')
res.download('/path/to/file')

// Headers
res.set('Content-Type', 'application/json')
res.cookie('token', value, { httpOnly: true })
💡 res.json() automatically sets Content-Type
✅ Always set appropriate status codes
⚡ Use streaming for large files
Back to the full Express.js cheat sheet