In Express.js, res.render() loads a view template, fills it with data (locals), and sends the HTML to the client. It is the usual way to return pages when you use EJS, Pug, Handlebars (hbs), and similar engines.
Optional. Template path relative to views (or absolute). Extension optional if view engine is set.
locals
Optional. Optional data for the template. Merges with app.locals and res.locals.
callback
Optional. Optional (err, html). When present, Express does not auto-send the response.
view engine
Required. Default engine name (e.g. ejs, pug)
views
Required. Template directory (default: ./views)
view cache
Required. Caches compiled templates (on by default in production)
Return Value
Without a callback, res.render() renders a view and sends HTML for you (async). With a callback (err, html), Express does not auto-send — your callback owns the response. Either way, do not treat it as a synchronous HTML string return.
GET /preview
→ callback receives html string
→ res.send(html) → 200 HTML body
(on error → 500 "Render error")
How It Works
Callback disables auto-send. You own the response.
Handle err first. Return early so you never send twice.
Send html yourself. Often via res.send(html) or res.type('html').
Use for post-processing. Same pattern as app.render(), which never sends on its own.
Compatibility
Runtime Support
res.render() is an Express.js response method. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers only receive the finished HTML.
✓ Server · Express 4 & 5
res.render()
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.render()Express on Node.js
Bottom line: Study and run these examples with Node.js, express, and a view engine such as ejs. Copy a snippet into a local file and start the server with node.
Frequently Asked Questions
It finds a view template, fills it with local variables, and sends the rendered HTML to the client. Without a callback, Express sends the response for you.
Yes. Set app.set('view engine', 'ejs') (or pug, hbs, and so on) and keep templates under the views folder (or app.set('views', …)).
res.send() sends a string/buffer/object you already have. res.render() loads a template file, merges data, then sends HTML.
Express does not auto-send. Your callback gets (err, html). You must res.send(html) yourself, and handle errors.
No. It runs on your Express server. The browser only receives the finished HTML response.