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

@commander-lol/koa-mustache

v1.0.3

Published

Mustache rendering for Koa 2+

Readme

koa-mustache

Mustache template rendering for Koa 2+

Installation

npm i --save @commander-lol/koa-mustache

Example

const path = require('path')
const Koa = require('koa')
const mustache = require('@commander-lol/koa-mustache')

const app = new Koa()

const templatePath = path.join(__dirname, 'views')
app.use(mustache(templatePath))

// Respond to all requests with the template at `./views/index.mustache`
app.use(async ctx => {
  await ctx.render('index')
})

Usage

  • Require the module const mustache = require('@commander-lol/koa-middleware')
  • Call the function to configure the middleware const middleware = mustache(myTemplateDirectoryPath, myOpts)
  • Mount the middleware on your app app.use(middleware)
  • The ctx.render function has been added to all subsequent middleware (including routes when using routers). await this function to render the specified params to the ctx body. If the template is not found, the status will be set to 404. If the template path is not a regular file, the status will be set to 500.

Types

These are the types that you need to be aware of to use koa-mustache. The export of this module (the object imported by require('@commander-lol/koa-mustache')) is of the type ConfigureMiddleware.

Configuration Options

type Options = {
  debug(...args: any[]): void,
  useCache?: boolean,
  extension?: string,
  partials?: string,
}

Module Export

type ConfigureMiddleware = (root: string, opts?: Options): KoaMiddleware

Render Function

type RenderTemplate = (template: string, data: Object): Promise<void>

Options

name | type | default | notes -----|------|---------|------ debug|Function|noop|Will receive debug information. Typically printed with console.log, but could be sent elsewhere useCache|boolean|if NODE_ENV is equal to production, true otherwise false|Will load templates on server boot, and exclusively use the in-memory cache for retrieving templates to render. Partials will always be loaded on boot extension|string|.mustache|The file extension to use when loading templates (Must include leading dot) partials|string|partials|The path, relative to the middleware root, where partials are located