app.engine(ext, callback) registers a template engine for a file extension. When you call res.render() (or app.render()), Express uses that callback to turn a view file into HTML.
By default, Express can require() engines that export __express (for example Pug). Use app.engine() when you want to map another extension (EJS → .html) or adapt an engine that does not follow the Express convention.
Syntax
Call app.engine in your Express.js app. Start with this line.
Express
app.engine(ext, callback)
Call
What it does
app.engine(ext, callback)
Primary signature.
Install with npm install express. Create the app with const app = express() before you use this API in an Express.js tutorial project.
views/hello.txt
<p>{{message}}</p>
GET /
→ <p>Custom engine works</p>
How It Works
Match the signature. Express calls (filePath, options, callback).
Read the file. The engine loads the template from disk.
Produce HTML. Replace placeholders, then call callback(null, html) (or callback(err) on failure).
Render as usual.res.render('hello') finds hello.txt via view engine.
Compatibility
Runtime Support
app.engine() is an Express.js application method. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers only receive rendered HTML.
✓ Server · Express 4 & 5
app.engine()
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.engine()Express on Node.js
Bottom line: Install an engine package (ejs, pug, …), register it if needed, then run your app with node.
Frequently Asked Questions
It registers a template engine callback for a file extension so Express can render matching view files.
Not always. Engines that export __express (like Pug or EJS for .ejs files) can be loaded automatically after you set view engine. Use app.engine() to map another extension or wire engines that need an adapter.
app.engine() teaches Express how to render an extension. app.set('view engine', ext) chooses the default extension used by res.render() when you omit one.
Express expects (path, options, callback), where callback is (err, html). EJS renderFile and engine.__express follow that shape.
No. It configures your Express server on Node.js. Browsers only receive the rendered HTML.