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

muws

v0.5.31

Published

A Mustache template engine with slots for Node.js

Readme

MuwS - a fast, streaming Node.js Mustache engine (with slots)

Build Status

About slots

If your a use Mustache for generating html, your are must use construction like this:

###template.mustashe:

{{>header}}{{!include html before content}}
content text
{{>footer}}{{!include html after content}}

###header.mustashe:

<html>
    <head>
    </head>
    <body>

###footer.mustashe:

    </body>
</html>

It is ugly, and split tags. I suggest use the slot mechanism.

###template.mustashe:

{{@parent}}{{!include parent template}}
{{[content}}content text{{/content}}{{!fill content slot}}
{{/parent}}

###parent.mustashe:

<html>
    <head>
    </head>
    <body>
    {{]content}}default content{{/content}}{{!define content slot}}
    </body>
</html>

Install

npm install muws

Usage

There are a few ways to use mu 0.5. Here is the simplest:

var mu = require('muws');

mu.root = __dirname + '/templates'
mu.compileAndRender('index.html', {name: "john"})
  .on('data', function (data) {
    console.log(data.toString());
  });

Here is an example mixing it with the http module:

var http = require('http')
  , util = require('util')
  , mu   = require('muws');

mu.root = __dirname + '/templates';

  http.createServer(function (req, res) {

  var stream = mu.compileAndRender('index.html', {name: "john"});
  stream.pipe(res);

}).listen(8000);

Taking that last example here is a little trick to always compile the templates in development mode (so the changes are immediately reflected).

var http = require('http')
  , util = require('util')
  , mu   = require('muws');

mu.root = __dirname + '/templates';

http.createServer(function (req, res) {

  if (process.env.NODE_ENV == 'DEVELOPMENT') {
    mu.clearCache();
  }

  var stream = mu.compileAndRender('index.html', {name: "john"});
  stream.pipe(res);

}).listen(8000);

Usage in express (http://expressjs.com/)

###start.js:

var express = require('express');
var app = express();
var mu   = require('muws');
app.engine('mustache', mu.__express);

app.get('/', function(req, res){
    res.render('index.mustache', {text:'Hello World'});
});

app.listen(8000);

###views/index.mustashe:

<html>
    <head>
    </head>
    <body>
    {{text}}
    </body>
</html>

API

mu.root

  A path to lookup templates from. Defaults to the working directory.

mu.globals

  A object. Fields from this object will use in each view in application.

mu.compileAndRender(String templateName, Object view)

  Returns: Stream

  The first time this function is called with a specific template name, the
  template will be compiled and then rendered to the stream. Subsequent
  calls with the same template name will use a cached version of the compiled
  template to improve performance (a lot).


mu.compile(filename, callback)

  Returns nil
  Callback (Error err, Any CompiledTemplate)

  This function is used to compile a template. Usually you will not use it
  directly but when doing wierd things, this might work for you. Does not
  use the internal cache when called multiple times, though it does add the
  compiled form to the cache.


mu.compileText(String name, String template, Function callback)

  Returns nil
  Callback (err, CompiledTemplate)

  Similar to mu.compile except it taks in a name and the actual string of the
  template. Does not do disk io. Does not auto-compile partials either.


mu.render(Mixed filenameOrCompiledTemplate, Object view)

  Returns Stream

  The brother of mu.compile. This function takes either a name of a template
  previously compiled (in the cache) or the result of the mu.compile step.

  This function is responsible for transforming the compiled template into the
  proper output give the input view data.

mu.renderSync(Mixed filenameOrCompiledTemplate, Object view)

  Returns rendered string

  Synchronous version of mu.render.

mu.renderText(String template, Object view, Object partials)

  Returns Stream

  Like render, except takes a template as a string and an object for the partials.
  This is not a very performant way to use mu, so only use this for dev/testing.


mu.clearCache(String templateNameOrNull)

  Clears the cache for a specific template. If the name is omitted, clears all cache.