Appearance
Node / Express
The express-nunjucks starter kit is a complete server-rendered Node project. Express and Nunjucks are the only dependencies; the stylesheet and the runtime are finished files, so there is no bundler in front of them. The same shape works with Fastify, Koa, EJS or Pug — only the template syntax moves.
Install
bash
npm run build:dist
npm run create -- my-admin --kit=express-nunjucks
cd my-admin
npm install
npm start # http://localhost:3000server.js routes, static mount, template config
views/
├── layouts/base.njk the shell — head, boot script, asset links
├── partials/{sidebar,topbar,footer}.njk
└── pages/{dashboard,orders,settings}.njk
public/assets/adminvora/ the compiled bundle (css, js, img, vendor)Server
js
// server.js
nunjucks.configure(join(here, 'views'), {
autoescape: true,
express: app,
noCache: process.env.NODE_ENV !== 'production'
});
// The bundle carries no fingerprint and changes only when you replace it.
app.use('/assets', express.static(join(here, 'public/assets'), { maxAge: '1y', immutable: true }));
// One value decides both the page title and the sidebar's active row.
const page = (view, active) => (req, res) => res.render(`pages/${view}.njk`, { active });
app.get('/', page('dashboard', 'dashboard'));
app.get('/orders', page('orders', 'orders'));Keep js/ and vendor/ siblings under the assets mount: the runtime lazy-loads ../vendor/… relative to its own URL.
Navigation
njk
<li class="av-menu__item {{ 'av-menu__item--active' if active == 'orders' }}">
<a class="av-menu__link" href="/orders" {{ 'aria-current="page"' | safe if active == 'orders' }}>
<span class="av-menu__label">Orders</span>
</a>
</li>Real data
views/pages/orders.njk ships literal rows so the kit runs with no database. Replace the <tbody> with a loop over your own data — the data grid enhances whatever rows it finds. Keep data-av-value on sortable cells:
njk
{% for order in orders %}
<tr>
<th scope="row" data-av-key="id" data-av-value="{{ order.id }}">#{{ order.id }}</th>
<td data-av-key="total" data-av-value="{{ order.totalCents }}">{{ order.totalDisplay }}</td>
</tr>
{% endfor %}Flash messages as toasts
njk
{% if flash %}
<script nonce="{{ nonce }}">
document.addEventListener('DOMContentLoaded', function () {
{% for f in flash %}AdminVora.toast.show({{ f | dump | safe }});{% endfor %}
});
</script>
{% endif %}Each f is { type, message } with type one of success, danger, warning, info. dump serialises it as JSON.
Live notifications
The runtime opens no connections. Stream events from your own endpoint and raise a toast as each arrives — see Notifications. Behind nginx, send X-Accel-Buffering: no and a keepalive comment every few seconds.
Content Security Policy
The boot script is inline by necessity — it must set the theme attributes before the first paint. With helmet, generate a nonce per request and add nonce="{{ nonce }}" to that one <script>:
js
app.use((req, res, next) => {
res.locals.nonce = crypto.randomBytes(16).toString('base64');
next();
});Checklist
- [ ] Boot script is the first script in
<head>, inline, with a nonce under CSP - [ ]
js/andvendor/are siblings under the assets mount - [ ] Nunjucks
autoescapeis on - [ ] Sortable and filterable cells carry
data-av-value - [ ] Every query is scoped by tenant on the server
Read next: React.