UNPKG

4.7 kBMarkdownView Raw
1buffet
2======
3
4Performance-oriented static file server
5
6[![build status](https://secure.travis-ci.org/carlos8f/node-buffet.png)](http://travis-ci.org/carlos8f/node-buffet)
7
8Idea
9----
10
11Serving static files should be the most efficient thing that a Node.js app can
12do. Turns out, runtime syscalls to the filesystem can really hang your page
13loads, especially if your filesystem is networked or unreliable in some other way.
14
15Buffet takes a fully-bufferred approach -- all files are fully loaded into
16memory when your app boots, so you will never feel the burn of the filesystem.
17In practice, this is immensely efficient. So much so that putting
18[Varnish](https://www.varnish-cache.org/) in front of your app might even make it
19slower! Well, almost (summary from buffet's `make bench`):
20
21```
22**************** varnish (5876.03 rps)
23**************** buffet-server (5587.53 rps)
24************** buffet (5008.57 rps)
25********** node-static (3643.76 rps)
26****** send (2130.13 rps)
27***** ecstatic (1690.86 rps)
28*** paperboy (737.16 rps)
29```
30
31Continuous deployment is also becoming all the rage, and restarting Varnish is
32a pain, so consider using Buffet -- your pages will always be fresh and zesty!
33
34Usage
35-----
36
37### Middleware
38
39Middleware version (compatible with [connect](http://www.senchalabs.org/connect/),
40[union/flatiron](http://flatironjs.org/), [middler](https://npmjs.org/package/middler), etc.)
41
42```javascript
43var connect = require('connect')
44 , app = connect()
45 , buffet = require('buffet')() // root defaults to ./public
46
47app.use(buffet);
48app.use(buffet.notFound);
49
50var server = require('http').createServer(app);
51server.listen(3000, function () {
52 console.log('test server running on port 3000');
53});
54```
55
56### Easy built-in server
57
58```bash
59$ npm install -g buffet
60$ cd /var/www/html && buffet
61buffet 0.4.0 listening on port 8080
62```
63
64### As a request handler
65
66```javascript
67var server = require('http').createServer();
68var buffet = require('buffet')(); // root defaults to ./public
69
70server.on('request', buffet);
71server.on('request', buffet.notFound);
72
73server.listen(3000, function () {
74 console.log('test server running on port 3000');
75});
76```
77
78Options
79-------
80
81- `root`: Document root. Can also be passed as the first parameter to `buffet()`.
82 (Default: `./public`)
83- `indexes`: True to look for `options.index` and serve it for directory requests.
84 (Default: true)
85- `index`: Name of index file to look for. (Default: `index.html`)
86- `gzip`: True to enable gzip when clients can accept it. (Default: `true`)
87- `watch`: True to auto-update the buffer when files change. (Default: `true`)
88- `poweredBy`: True to add the `X-Powered-By` header. (Default: `true`)
89- `maxAge`: Number of max-age seconds to set `Cache-Control` header. Set to
90 `false` or `0` to disable. (Default: `300`)
91- `notFoundPath`: Path to be rendered on `buffetMiddleware.notFound`. (Default:
92 `/404.html`)
93- `keepAlive`: Timeout (in milliseconds) for HTTP keep-alive. (Default: `5000`)
94
95Running your own benchmark
96--------------------------
97
98Type `make bench` in the buffet directory (you'll need
99[siege](http://www.joedog.org/siege-home/) installed).
100
101Brought to you by [benchmarx](https://github.com/carlos8f/node-benchmarx).
102
103See [here](https://gist.github.com/3473500) for my results.
104
105- - -
106
107### Developed by [Terra Eclipse](http://www.terraeclipse.com)
108Terra Eclipse, Inc. is a nationally recognized political technology and
109strategy firm located in Aptos, CA and Washington, D.C.
110
111- - -
112
113### License: MIT
114
115- Copyright (C) 2012 Carlos Rodriguez (http://s8f.org/)
116- Copyright (C) 2012 Terra Eclipse, Inc. (http://www.terraeclipse.com/)
117
118Permission is hereby granted, free of charge, to any person obtaining a copy
119of this software and associated documentation files (the "Software"), to deal
120in the Software without restriction, including without limitation the rights
121to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
122copies of the Software, and to permit persons to whom the Software is furnished
123to do so, subject to the following conditions:
124
125The above copyright notice and this permission notice shall be included in
126all copies or substantial portions of the Software.
127
128THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
129IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
130FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
131AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
132LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
133OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
134SOFTWARE.
\No newline at end of file