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

h5bp

v0.1.4

Published

HTML5 boilerplate (H5BP) inspired server config for node.js

Downloads

32

Readme

H5BP Version Badge

HTML5 boilerplate (H5BP) server config for node.js.

NPM

Build Status Dependency Status devDependency Status

h5bp for node.js follows the guidelines of the Apache version:

  • secures backup and hidden files.
  • optionally redirects www.yoursite.tld to yoursite.tld or vice versa.
  • offers a simple cache busting mechanism.
  • normalize content types.
  • optionally enables CORS.
  • sets correct cache expires depending of the type of resource.
  • and some others...

It also focuses on offering additional features such as on-the-fly script concatenation using CommonJS or AMD.

Next release focus (v0.1.3)

  • refactoring code and tests.
  • responsive images: #13.

Installation

npm install --save h5bp

Quick Start

Create a simple http server

var h5bp = require('h5bp');

var app = h5bp.createServer({ root: __dirname + '/public' });
app.listen(3000);

app is an instance of an express application. You can add additional middlewares or routes if you like.

Use it as a connect / express middleware

var express = require('express'),
    h5bp = require('h5bp');

var app = express();
app.use(h5bp({ root: __dirname + '/public' }));

// in order to serve files, you should add the two following middlewares
app.use(express.compress());
app.use(express.static(__dirname + '/public'));
app.listen(3000);

Concatenate scripts on-the-fly

If you want to split your application source files but only serve one file, you can use the on-the-fly concatenation. If you are familiar with node.js, you can use the CommonJS style. You can also use the AMD style.

app.use(h5bp({
    root: __dirname + '/public',
    scripts: {
        files: ['app.js'],
        processor: 'commonjs'   // can also be "amd"
    }
}));

At the first request hit to /app.js, the server will compile, cache and serve the file. Any subsequent request will serve the cached file without any performance impact.

So, this feature is meant to be used with the cache busting mechanism in order to ensure the client always has the latest resource version. If you restart your server, the cache will be flushed.

Note that the next release will provide a development mode where the server will simply disable its cache and always serve the latest version of the file.

Options

There are several options you can pass to the middleware.

app.use(h5bp(options));

root

Tells the filesystem path to the root directory of static resources. This options is mandatory if you serve static files.

www

Forces www if true, forces non-www if false, does nothing if not defined. By default, this is disabled.

cors

Enables CORS for everything. By default this is disabled.

dotfiles

Enables access to dotfiles. By default this is disabled.

scripts

Tells which scripts to concatenate.

This is an object with the following properties:

files

This is an array of files to concatenate. Their path is relative to the root option. Their URL will be absolute.

For example, if you set files to ['scripts/app.js'] and root to /home/h5bp/app/:

  • The path will be: /home/h5bp/app/scripts/app.js.
  • The served URL will be: yoursite.tld/scripts/app.js.

processor

Tells which processor to use for scripts concatenation.

For now, it can be one of the following values:

  • commonjs: will concatenate files using the CommonJS method (require/exports).
  • amd: will concatenate files using the AMD method (require/define).

Additional options

The h5bp.createServer function takes the same options, plus additional ones.

The callback is optional. It is a custom middleware that you can register directly if you want to.

h5bp.createServer(options, [callback]);

server

Tells which type of server you want to use.

It can be one of the following values:

  • express: uses express, this is the default value.
  • connect: uses connect.

logger

Tells if you want to log server requests or not. This can also be an object containing logger options.

compress

Tells if you want to serve gzipped content or not. By default this is true.

If you are using h5bp as a middleware, we strongly encourage you to use the compress middleware provided by express / connect.

License

MIT License