Registry / web-framework / koa-pug

koa-pug

JSON →
library5.1.1jsnpmunverified

Koa-pug is a Pug (formerly Jade) template engine middleware for Koa (v1 and v2) JavaScript web frameworks. Current stable version is 5.1.1, released in 2019, with infrequent updates (last commit 2019). It integrates Pug templates into Koa by binding ctx.render() and supports custom view paths, global helpers via helperPath, and standalone rendering. Key differentiators: seamless Koa integration, helper auto-loading from directories, and Pug@3 support. Alternatives like @ladjs/koa-pug-view are more actively maintained.

npm install koa-pug
INSTALL
IMPORT
SIG · KOA-PUG
K
koa-pug
web-frameworkjavascriptv5.1.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
const Pug = require('koa-pug')
import Pug from 'koa-pug'
CommonJS only; package does not provide ESM exports. Use require().
default
import Pug from 'koa-pug'
import { Pug } from 'koa-pug'
Default export only; no named exports. Works with ESM loader but required CJS module.
default
const Pug = await import('koa-pug')
const { Pug } = await import('koa-pug')
Dynamic import returns default export as module.default; destructure not needed.

Sets up a Koa server with Pug template rendering using koa-pug middleware.

const Koa = require('koa'); const Pug = require('koa-pug'); const path = require('path'); const app = new Koa(); const pug = new Pug({ viewPath: path.resolve(__dirname, './views'), locals: { title: 'Hello' }, app: app }); app.use(async ctx => { await ctx.render('index', { message: 'World' }); }); app.listen(3000);
Debug
Known issues
deprecatedThe package is in maintenance mode; no active development since 2019.
fix
Consider using @ladjs/koa-pug-view for active support.
affects: >=4.0.0
breakingVersion 5.x drops support for Node <10 and requires Pug@3.
fix
Upgrade Node.js to >=10 and install Pug@3.
affects: >=5.0.0
gotchaThe `app` option must be passed to constructor to bind ctx.render(); otherwise, you must call pug.use(app) after instantiation.
fix
Pass { app: app } in options or call pug.use(app).
affects: >=1.0.0
gotchaWhen using helperPath, the module filename is converted to camelCase for the helper name. For example, 'format-date.js' becomes 'formatDate'.
fix
Use PascalCase or camelCase in filenames to avoid naming conflicts.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: render is not a function
Missing `app` option or `pug.use(app)` not called; ctx.render not bound.
fix
new Pug({ app: app }) or pug.use(app);
Error: Cannot find module 'pug'
Pug package is not installed as a dependency.
fix
npm install pug --save
Error: Could not find template 'index'
Template file not found in viewPath or incorrect path.
fix
Ensure viewPath is correct (defaults to process.cwd()) and template exists.
Upgrade
Version history
5.1.1latest on npm
Audit
Dependencies
pugrequiredRequired peer dependency for template compilation
koaoptionalOptional peer dependency; required only for Koa integration
Agent activity
2 hits · last 30 days
node
2
Resources
koa-pug — npm install koa-pug · libregistry