Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Express.js · Module

app.render

app.render() renders a named Express view and provides the resulting HTML to a callback. Unlike res.render(), it does not send the rendered view to the client automatically.

How it works

app.render renders a named view using the application’s configured view settings and optional local variables. Its callback receives either an error or the generated HTML, so the caller decides what to do with the result.

Syntax

app.render(view, [locals], callback)

Parameters

NameTypeDescription
viewStringName of the view to render.
localsObject | undefinedOptional object whose properties define local variables for the view.
callbackFunctionCallback invoked as callback(err, html).

Returns

The rendered HTML of a view is provided through the callback function.

Key points

  • view identifies the template or view name that Express should render.
  • locals supplies values that the view can access while it is rendered.
  • The callback receives an error value and the resulting HTML string.
  • Rendered output is delivered asynchronously through the callback.
  • It can be used as a general-purpose view-to-string utility.
  • Express builds response rendering on top of the application-level renderer.

Common mistakes

  • Unlike res.render(), app.render does not send the generated HTML automatically; the callback must handle it.

Example: Render a view without sending it automatically

const express = require('express');
const app = express();

app.set('views', __dirname + '/views');
app.set('view engine', 'pug');

app.get('/preview', (req, res, next) => {
  app.render('email', { name: 'Ada' }, (err, html) => {
    if (err) return next(err);
    res.type('html').send(html);
  });
});

app.listen(3000);

Renders the configured email view to an HTML string, then sends that string explicitly.

When to use it

Create reusable rendered content

Generate HTML for an email or another non-HTTP output before handing it to a delivery system.

Prepare a custom response

Render a template into a string so application code can inspect or transform it before responding.

Preview rendered views

Produce a server-side preview while retaining control over when and how the HTML is sent.

Interview questions

QWhat does app.render do, and what does its callback receive?

app.render(view, locals, callback) generates a view’s HTML and passes it to the callback as callback(err, html). It is useful when the rendered output must be handled by application code rather than sent directly.

Follow-up: How does it relate to res.render()? res.render() uses app.render() internally, while app.render() itself only produces the rendered string.

QWhat are the view and locals arguments used for?

The view argument is the name of the view to render. The optional locals object supplies properties that become local variables available to that view.

Follow-up: What should be done when rendering fails? Check err first and handle or forward it before using html.

QHow is app.render different from sending a response with res.render()?

The method returns rendered HTML through its callback rather than as a direct synchronous return value. This lets the caller choose whether to send, store, transform, or otherwise process the generated string.

Follow-up: Why might an application use this instead of res.render()? It can generate content for non-response work, such as composing an email or previewing output.

  • res.render
  • app.set
  • view engine
  • views

Source: Application Object · Express.js 4.x. Checked 2026-10-15.