Explore Related Tools
Hand-picked utilities and calculators related to this tool.
The res object represents the HTTP response that an Express app sends when it gets an HTTP request.
| Method | Purpose | Example |
|---|---|---|
res.send() | Send a response of various types | res.send('Done') |
res.json() | Send a JSON response (Best for APIs) | res.json({ id: 1 }) |
res.status() | Set the HTTP status code | res.status(404) |
res.render() | Render a view template | res.render('index') |
res.redirect() | Redirect to a different URL | res.redirect('/login') |
res.sendFile() | Send a file as an octet stream | res.sendFile(path) |
You can chain methods together to set a status and send data in one line.
app.get('/api/users', (req, res) => {
res.status(201).json({ message: 'User created' });
});Use res.redirect() to move users between pages, such as after a successful form submission.
app.get('/old-page', (req, res) => {
res.redirect(301, '/new-page'); // Permanent redirect
});res.json() when building APIs, as it automatically sets the Content-Type to application/json.Hand-picked utilities and calculators related to this tool.
