Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add example

  • Loading branch information...
commit 7f1afd20620417d188c2a2ecc466d9d8008c8cc9 1 parent 347cb7c
@tj tj authored
Showing with 32 additions and 1 deletion.
  1. +32 −1 Readme.md
View
33 Readme.md
@@ -1,7 +1,38 @@
# send
- Better streaming static file server with Range and conditional-GET support.
+ Better streaming static file server for node with Range and conditional-GET support.
+
+## Installation
+
+ $ npm install send
+
+## Example
+
+```js
+var app = http.createServer(function(req, res){
+ // your custom error-handling logic:
+ function error(err) {
+ res.statusCode = err.status || 500;
+ res.end(err.message);
+ }
+
+ // your custom directory handling logic:
+ function redirect() {
+ res.statusCode = 301;
+ res.setHeader('Location', req.url + '/');
+ res.end('Redirecting to ' + req.url + '/');
+ }
+
+ // transfer arbitrary files from within
+ // /www/example.com/public/*
+ send(url.parse(req.url).pathname)
+ .root('/www/example.com/public')
+ .on('error', error)
+ .on('directory', redirect)
+ .pipe(res);
+});
+```
## About
Please sign in to comment.
Something went wrong with that request. Please try again.