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 🙏

© 2024 – Pkg Stats / Ryan Hefner

metaserve

v0.8.5

Published

compile & serve metalanguage assets

Downloads

102

Readme

metaserve

metaserve makes web application prototyping quicker by compiling and serving assets built with meta-languages[1] such as CoffeeScript, Jade, and Styl (currently the full list).

Use as a command or as middleware to handle requests for e.g. js/myapp.js by run-time-compiling the js/myapp.coffee source file into Javascript. Similar to (but less contrived than) the Rails Asset Pipeline.

Metaserve is based on a collection of plugins, which by default support Jade (to HTML), CoffeeScript (to Javascript), and Sass (to CSS) to support the Prontotype stack. New languages are easily added with a simple plugin architecture.

As a command

Install with npm install -g metaserve

Use within a directory that has a bunch of .jade, .sass and .coffee. Run metaserve with optional arguments --host and --port. Defaults to 0.0.0.0:8000.

As middleware

Install with npm install metaserve

Use by supplying a base directory, then hooking it in as Express/Connect middleware...

var express = require('express');
var metaserve = require('metaserve');

app = express();
app.use(metaserve('./app'));
app.listen(8550);

... or as a fallback method in a standard http server:

var http = require('http');
var metaserve = require('metaserve')('./app');

var server = http.createServer(function(req, res) {
    if (req.url === '/dogs') {
        return res.end('woof');
    } else {
        return metaserve(req, res);
    }
});

server.listen(8550);

Writing Plugins

A plugin is simply a Javascript module with a few fields:

  • ext
    • The extension that this plugin will match, e.g. "coffee"
  • default_config (optional)
    • Default config which will be extended and passed in as the config argument to the compiler function
  • compiler(filename, config, context, cb)
    • A function that should transform some source file and call back with an object {content_type, compiled}

Here's a simple plugin that reads and reverses a text file:

var fs = require('fs');

module.exports = {
    ext: 'txt',

    compile: function(filename, config, context, cb) {
        fs.readFile(filename, function(err, source) {
            if (err)
                return cb(err);
            else {
                source = source.toString();
                reversed = source.split('').reverse().join('')
                cb(null, {
                    content_type: 'text/plain',
                    compiled: reversed
                });
            }
        });
    }
};

By passing an object of compilers to the metaserve middleware, paths that match the extension key (here "txt") will be run through this plugin:

app.use(metaserve('./app', {
    txt: require('./reverse-plugin')
}));

Default Plugins


Notes

  1. Not to be confused with the real definition of a Metalanguage.