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 🙏

© 2026 – Pkg Stats / Ryan Hefner

express-content-router

v1.1.0

Published

Generate express router from js files in a directory

Readme

express-content-router

Generate an express.js router object from a specially formed directory of content object files.

Expects to be used at any mount point as an express router.

Basic usage:

var app = express();
var router = require('express-content-router')(__dirname + "/content");
app.use('/mountpoint/', router);

Also supports an options hash as the second param. Currently only option supported is "sitemap" which should be a valid express view file name reference, to render a test sitemap page at the /sitemap path.

Content Structure

Content is specified in a specific directory, and the actual directory structure determines the page URLs.

Example:

You want an /index.html and /about-us/index.html to be the URLs on your application.

Your directory structure would be the following:

/content/index.js
/content/about-us/index.js

Any level of nesting can be used.

One important caveat - Don't name a file the same thing as a directory at the same level - the directory's content will overwrite the file. This is due to the default behavior of the require-dir module with respect to recursion.

If you do want to have similarly named URLs generated from a filename and directory (both /about.html and /about/detail.html for example), prefix the filename with "@" to avoid the conflict. The library will compensate and generate the expected URL paths.

If you want to have individual blocks of content that are shared between pages (common header/footer, contact, etc), you can put that directly in an underscore-prefixed file at any level, and require it in your main page content object. The underscored files will be ignored by the router, but will be required into each page automatically.

... directory setup

/content/_footer-links.js
/content/page.js

... and in page.js

module.exports = {
    ...
    content: {
        footerLinks: require('./_footer-links')
    }
}

Page Object Spec

An object that defines a page should resemble the following:

module.exports = {
    // view defines the express view file in your application to render this page
    view: "view-file-name",
    // page title is used for the <head><title> content
    title: "Page Title",
    // content is passed to the express view template for rendering
    // can contain whatever you need for your project.
    content: {
        title: "My Awesome Page",
        leadParagraph: "Isn't it awesome?"
    }
}

Roadmap / TODOs

  • Support more features and auto-generated content for building page navigation structures.

  • Support meta tag definition in the page spec

  • Global configuration scheme for common site things across all pages. Meta tags, Titles, navigation

  • Support storing content in a database of some kind instead of the file system.

  • Support passing in optional global properties for view rendering

  • Option flag to auto-generate navigation object data