npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

express-page-registry

v0.1.1

Published

Bind Express routes to views and auto-register pages for nav & sitemap.

Downloads

109

Readme

express-page-registry

A tiny helper for Express that binds routes to views and automatically registers every page for easy navigation, sitemaps, or debugging.


✨ Features

  • 🧩 Single function to bind a route and render a view.
  • 🗂️ Keeps a central registry of all bound pages.
  • 📜 Build dynamic nav menus or generate sitemap.xml.
  • 🧠 Supports per-request locals via getData(req, res).
  • 🧱 Framework-agnostic — works with any Express view engine (EJS, Pug, Handlebars, etc).

📦 Installation

npm i express-page-registry

🚀 Quick Start

const path = require('path');
const express = require('express');
const { bind, registry } = require('express-page-registry');

const app = express();
const router = express.Router();

app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));

// Example route
bind(router, {
  route: '/',
  view: 'home',
  meta: { title: 'Home · MySite', description: 'Welcome to MySite!' },
  nav: { label: 'Home', order: 1, visible: true },
  getData: (req) => ({
    user: req.user || null,
    csrfToken: typeof req.csrfToken === 'function' ? req.csrfToken() : null,
    message: 'Hello from express-page-registry!'
  })
});

app.use(router);

// optional dev route to inspect registered pages
app.get('/_pages.json', (_req, res) => res.json(registry.all()));

app.listen(3000, () => console.log('🚀 http://localhost:3000'));

🧠 API

bind(router, options)

Registers a page route and renders its view.

| Option | Type | Description | |--------|------|-------------| | route | string | The Express path (e.g. /about). | | view | string | The template file name (e.g. home, about). | | meta | object | Optional metadata (title, description, etc.). | | nav | { label, order, visible } | Optional navigation info. | | robots | { index: boolean } | Include in sitemap (default true). | | getData(req, res) | function | Async or sync function returning per-request locals. | | middleware | array | Optional Express middleware for this route. |


registry

The central store of all registered pages.

| Method | Description | |--------|-------------| | registry.all() | Returns all pages. | | registry.publicPages() | Returns only pages with nav.visible = true. | | registry.toSitemapXml(baseUrl) | Builds a simple XML sitemap string. | | registry.reset() | Clears all pages (useful in tests). |

Example:

console.table(registry.all());

💡 Example Directory

example/
├─ app.js
└─ views/
   └─ home.ejs

example/app.js

const path = require('path');
const express = require('express');
const { bind } = require('express-page-registry');

const app = express();
const router = express.Router();

app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));

bind(router, {
  route: '/',
  view: 'home',
  meta: { title: 'Home · Demo' },
  getData: () => ({ message: 'Hello World!' })
});

app.use(router);
app.listen(3000, () => console.log('http://localhost:3000'));

example/views/home.ejs

<!doctype html>
<html>
  <head><title><%= title %></title></head>
  <body>
    <h1><%= message %></h1>
  </body>
</html>

🛠️ License

MIT © 2025 Michael Hulbert
https://github.com/CloseRange