Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Performance-oriented static file server

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 bin
Octocat-spinner-32 examples
Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Makefile
Octocat-spinner-32 README.md
Octocat-spinner-32 package.json
README.md

buffet

Performance-oriented static file server

Idea

Buffet was borne out of frustration. Serving static files should be the most efficient thing that a Node.js app can do. Turns out, runtime syscalls to the filesystem can really hang your page loads, especially if you're getting that humongous burst of traffic you've been dreaming of, and your filesystem is networked or unreliable in some other way.

Buffet takes a fully-bufferred approach (hence the name, hehe) -- all files are fully loaded into memory when your app boots, so you will never feel the burn of the filesystem. In practice, this is immensely efficient. So much so that putting Varnish in front of your app might even make it slower!

Continuous deployment is also becoming all the rage, and restarting Varnish is a pain, so consider using Buffet instead, so your pages are always fresh and zesty.

Usage

Easy built-in server:

$ npm install -g buffet
$ cd /var/www/html
$ buffet
buffet 0.2.3 listening on port 8080

Middleware version (compatible with connect, union/flatiron, etc.)

var buffetMiddlware = buffet(root, {options...});
// also available to serve 404 pages:
buffetMiddleware.notFound(req, res);

Options

  • indexes: True to look for options.index and serve it for directory requests. (Default: true)
  • index: Name of index file to look for. (Default: index.html)
  • gzip: True to enable gzip when clients can accept it. (Default: true)
  • watch: True to auto-update the buffer when files change. (Default: true)
  • poweredBy: True to add the X-Powered-By header. (Default: true)
  • maxAge: Number of max-age seconds to set Cache-Control header. Set to false or 0 to disable. (Default: 300)
  • notFoundPath: Path to be rendered on buffetMiddleware.notFound. (Default: /404.html)
  • keepAlive: Send Connection: keep-alive header. (Default: true)

Example

var buffet = require('buffet')('/var/www/html', {maxAge: 86400})
  , http = require('http')
  , port = 9000
  ;

http.createServer(function(req, res) {
  buffet(req, res, buffet.notFound.bind(null, req, res));
}).listen(port, function() {
  console.log('test server running on port 9000');
});

License

MIT

Something went wrong with that request. Please try again.