res.redirect() tells the client to go to another URL. Express sets a redirect status (default 302 Found), sets the Location header, and ends the response.
Use it for moved routes, login gates, and post/redirect/get flows. To set Location without finishing the response, see res.location(). Status-only helpers live on res.status().
Syntax
Call res.redirect in your Express.js app. Start with this line.
Express
res.redirect(path)
res.redirect(status, path)
Call
What it does
res.redirect(path)
Primary signature.
res.redirect(status, path)
Related call form.
Install with npm install express. Create the app with const app = express() before you use this API in an Express.js tutorial project.
GET /account (no req.user)
→ 302 Location: /login
GET /account (req.user set)
→ Welcome to your account
How It Works
Check auth first. Missing user → redirect path.
return after redirect. Stops a second res.send (double-response bug).
302 keeps it temporary. Login gates are not permanent moves.
Logged-in users continue. The welcome body is sent only when allowed.
Compatibility
Runtime Support
res.redirect() is an Express.js response method. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers only follow the 3xx + Location they receive.
✓ Server · Express 4 & 5
res.redirect()
Works wherever Express runs: Node.js is the primary target. Bun and Deno can run many Express apps with compatibility layers. Not available in the browser.
ServerNode.js runtime API
Node.js18+ for Express 5 · 14+ typical for Express 4
Supported
BunExpress-compatible server apps
Supported
DenoVia npm compatibility / adapters
Supported
res.redirect()Express on Node.js
Bottom line: Study and run these examples with Node.js and the express package. Copy a snippet into a local file and start the server with node.
Frequently Asked Questions
It sends an HTTP redirect: sets a 3xx status (default 302), sets the Location header, and ends the response so the client follows the new URL.
302 Found. Pass a status first when you need another code, for example res.redirect(301, '/docs').
Use res.redirect(status, url) only — not res.redirect(url, status). The magic string 'back' was removed; use req.get('Referrer') || '/' instead.
res.location() only sets the Location header. res.redirect() sets Location, chooses a redirect status, and finishes the response.
No. It runs on your Express server. The browser receives the 3xx response and Location header, then requests the new URL.