send
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
debug | 2.6.9 | 16.13 kB | MIT | prod | |
depd | 2.0.0 | 8.18 kB | MIT | prod | |
destroy | 1.2.0 | 3.3 kB | MIT | prod | |
encodeurl | 1.0.2 | 3.18 kB | MIT | prod | |
escape-html | 1.0.3 | 1.87 kB | MIT | prod | |
etag | 1.8.1 | 4.28 kB | MIT | prod | |
fresh | 0.5.2 | 4.13 kB | MIT | prod | |
http-errors | 2.0.0 | 6.19 kB | MIT | prod | |
mime | 1.6.0 | 15.32 kB | MIT | prod | |
ms | 2.1.3 | 2.9 kB | MIT | prod | |
on-finished | 2.4.1 | 4.93 kB | MIT | prod | |
range-parser | 1.2.1 | 3.52 kB | MIT | prod | |
statuses | 2.0.1 | 4.57 kB | MIT | prod |
Send is an advanced static file server library for Node.js. It facilitates the streaming of files from the file system as an HTTP response. Key features include support for partial responses (Ranges), conditional-GET negotiation (If-Match, If-Unmodified-Since, If-None-Match, If-Modified-Since), strong test coverage, and fine-grained events. Send does not perform internal caching on its own, implying that for caching purposes, you would need to use a reverse proxy cache such as Varnish or a Content Delivery Network (CDN). Additionally, you are also given the ability to serve up entire directories and individual specific files.
To use send in your Node.js project, you need to first install the package using npm with the command npm install send
. Once installed, requiring the library in your javascript file can be carried out with the line var send = require('send')
. The general formula for usage is send(req, path, [options]).pipe(res)
, with replacement of req
, path
, and optionally options
with your desired parameters. Here's an example of using send to serve a specific file:
var http = require('http')
var send = require('send')
var server = http.createServer(function onRequest (req, res) {
send(req, '/path/to/index.html')
.pipe(res)
})
server.listen(3000)
In this instance, send is being used to send a specified file (/path/to/index.html
) to every request that is received on the server.
The complete documentation for Send library is available on its GitHub page at git+https://github.com/pillarjs/send.git as well as on the npm module page at https://www.npmjs.org/package/send. These locations provide all the required information on how to use, install and manipulate the send functions, as well as how to operate different features like custom error-handling, caching, debugging, event handling etc.