In Express.js, app.render(view, [locals], callback) renders a view to an HTML string and calls callback(err, html). Unlike res.render(), it does not send the response by itself.
Think of it as a utility for emails, PDF pipelines, or custom delivery. Internally, res.render() uses app.render(). You still need views + a view engine via app.set() and often app.engine().
Syntax
Call app.render in your Express.js app. Start with this line.
Required. Name of the view to render (resolved under the views directory / view engine).
locals
Optional. Optional. Local variables for the template (for example { name: 'Tobi' }).
callback
Required. (err, html) — error first, then the rendered HTML string.
Return Value
app.render() does not return HTML synchronously. You always pass a callback of the form (err, html) and use the rendered string there. The call itself is for side-effect rendering, not a usable return value.
Express
app.render('email', { name: 'Ada' }, (err, html) => {
if (err) throw err;
// html is the rendered string — send email, cache, etc.
});
Express.js Examples
Example 1 — Render to String
Official callback shape: get HTML without sending a response yet.
GET /preview
→ 200 text/html
(body = rendered hello view)
Tip: for a plain page with no extra steps,
prefer res.render('hello', { title: 'Preview' }).
How It Works
Route starts.GET /preview needs HTML.
app.render first. You receive the string in the callback.
Optional work. Transform or log before responding.
Send manually.res.send(html) finishes the response — or use res.render when you need none of that.
Compatibility
Runtime Support
app.render() is an Express.js application method. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers receive HTML only after you send it.
✓ Server · Express 4 & 5
app.render()
Works wherever Express runs: Node.js is the primary target. Bun and Deno can run many Express apps with compatibility layers.
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
app.render()Express on Node.js
Bottom line: Install a view engine (for example ejs), set views, then call app.render.
Frequently Asked Questions
It renders a view template to an HTML string and passes the result to a callback as callback(err, html). It does not send the response by itself.
res.render() renders and usually sends HTML to the client. app.render() only produces the string — useful for emails, logging, or custom delivery. Internally, res.render() uses app.render().
Yes. Set views and view engine (and app.engine when needed) the same way you would for res.render().
Yes. Pass an object as the second argument: app.render('email', { name: 'Tobi' }, callback).
No. Official docs warn that the view argument performs filesystem operations — never put end-user input in the view name.