{"name":"send","version":"0.19.2","keywords":["static","file","server"],"author":{"name":"TJ Holowaychuk","email":"tj@vision-media.ca"},"license":"MIT","_id":"send@0.19.2","maintainers":[{"name":"ulisesgascon","email":"ulisesgascondev@gmail.com"},{"name":"blakeembrey","email":"hello@blakeembrey.com"},{"name":"wesleytodd","email":"wes@wesleytodd.com"},{"name":"dougwilson","email":"doug@somethingdoug.com"}],"contributors":[{"name":"Douglas Christopher Wilson","email":"doug@somethingdoug.com"},{"name":"James Wyatt Cready","email":"jcready@gmail.com"},{"name":"Jesús Leganés Combarro","email":"piranna@gmail.com"}],"homepage":"https://github.com/pillarjs/send#readme","bugs":{"url":"https://github.com/pillarjs/send/issues"},"dist":{"shasum":"59bc0da1b4ea7ad42736fd642b1c4294e114ff29","tarball":"http://registry-npm.ywwl.com/send/download/send-0.19.2.tgz","fileCount":6,"integrity":"sha512-VMbMxbDeehAxpOtWJXlcUS5E8iXh6QmN+BkRX1GARS3wRaXEEgzCcB10gTQazO42tpNIya8xIyNx8fll1OFPrg==","signatures":[{"sig":"MEQCIBt8fagqiJhHKI9RO4IiK+oRAswrqEPGC5bMgpWUShpkAiB+P4Umo8Kz2K66h6QNkwexa8gZFJab/b/qE8DdIH8LHw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":50398,"size":15682,"noattachment":false,"key":"/send/-/send-0.19.2.tgz"},"engines":{"node":">= 0.8.0"},"gitHead":"34ba03b7579d31c8bb6d5a3ead573da1a7a118e7","scripts":{"lint":"eslint .","test":"mocha --check-leaks --reporter spec --bail","test-ci":"nyc --reporter=lcov --reporter=text npm test","test-cov":"nyc --reporter=html --reporter=text npm test"},"_npmUser":{"name":"ulisesgascon","email":"ulisesgascondev@gmail.com"},"repository":{"url":"git+https://github.com/pillarjs/send.git","type":"git"},"_npmVersion":"10.9.0","description":"Better streaming static file server with Range and conditional-GET support","directories":{},"_nodeVersion":"22.10.0","dependencies":{"ms":"2.1.3","depd":"2.0.0","etag":"~1.8.1","mime":"1.6.0","debug":"2.6.9","fresh":"~0.5.2","destroy":"1.2.0","statuses":"~2.0.2","encodeurl":"~2.0.0","escape-html":"~1.0.3","http-errors":"~2.0.1","on-finished":"~2.4.1","range-parser":"~1.2.1"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"15.1.0","after":"0.8.2","mocha":"9.2.2","eslint":"7.32.0","supertest":"6.2.2","eslint-plugin-node":"11.1.0","eslint-plugin-import":"2.25.4","eslint-plugin-promise":"5.2.0","eslint-config-standard":"14.1.1","eslint-plugin-markdown":"2.2.1","eslint-plugin-standard":"4.1.0"},"_npmOperationalInternal":{"tmp":"tmp/send_0.19.2_1765826944338_0.15226415514754832","host":"s3://npm-registry-packages-npm-production"},"readme":"# send\n\n[![NPM Version][npm-version-image]][npm-url]\n[![NPM Downloads][npm-downloads-image]][npm-url]\n[![CI][github-actions-ci-image]][github-actions-ci-url]\n[![Test Coverage][coveralls-image]][coveralls-url]\n\nSend is a library for streaming files from the file system as a http response\nsupporting partial responses (Ranges), conditional-GET negotiation (If-Match,\nIf-Unmodified-Since, If-None-Match, If-Modified-Since), high test coverage,\nand granular events which may be leveraged to take appropriate actions in your\napplication or framework.\n\nLooking to serve up entire folders mapped to URLs? Try [serve-static](https://www.npmjs.org/package/serve-static).\n\n## Installation\n\nThis is a [Node.js](https://nodejs.org/en/) module available through the\n[npm registry](https://www.npmjs.com/). Installation is done using the\n[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):\n\n```bash\n$ npm install send\n```\n\n## API\n\n```js\nvar send = require('send')\n```\n\n### send(req, path, [options])\n\nCreate a new `SendStream` for the given path to send to a `res`. The `req` is\nthe Node.js HTTP request and the `path` is a urlencoded path to send (urlencoded,\nnot the actual file-system path).\n\n#### Options\n\n##### acceptRanges\n\nEnable or disable accepting ranged requests, defaults to true.\nDisabling this will not send `Accept-Ranges` and ignore the contents\nof the `Range` request header.\n\n##### cacheControl\n\nEnable or disable setting `Cache-Control` response header, defaults to\ntrue. Disabling this will ignore the `immutable` and `maxAge` options.\n\n##### dotfiles\n\nSet how \"dotfiles\" are treated when encountered. A dotfile is a file\nor directory that begins with a dot (\".\"). Note this check is done on\nthe path itself without checking if the path actually exists on the\ndisk. If `root` is specified, only the dotfiles above the root are\nchecked (i.e. the root itself can be within a dotfile when set\nto \"deny\").\n\n  - `'allow'` No special treatment for dotfiles.\n  - `'deny'` Send a 403 for any request for a dotfile.\n  - `'ignore'` Pretend like the dotfile does not exist and 404.\n\nThe default value is _similar_ to `'ignore'`, with the exception that\nthis default will not ignore the files within a directory that begins\nwith a dot, for backward-compatibility.\n\n##### end\n\nByte offset at which the stream ends, defaults to the length of the file\nminus 1. The end is inclusive in the stream, meaning `end: 3` will include\nthe 4th byte in the stream.\n\n##### etag\n\nEnable or disable etag generation, defaults to true.\n\n##### extensions\n\nIf a given file doesn't exist, try appending one of the given extensions,\nin the given order. By default, this is disabled (set to `false`). An\nexample value that will serve extension-less HTML files: `['html', 'htm']`.\nThis is skipped if the requested file already has an extension.\n\n##### immutable\n\nEnable or disable the `immutable` directive in the `Cache-Control` response\nheader, defaults to `false`. If set to `true`, the `maxAge` option should\nalso be specified to enable caching. The `immutable` directive will prevent\nsupported clients from making conditional requests during the life of the\n`maxAge` option to check if the file has changed.\n\n##### index\n\nBy default send supports \"index.html\" files, to disable this\nset `false` or to supply a new index pass a string or an array\nin preferred order.\n\n##### lastModified\n\nEnable or disable `Last-Modified` header, defaults to true. Uses the file\nsystem's last modified value.\n\n##### maxAge\n\nProvide a max-age in milliseconds for http caching, defaults to 0.\nThis can also be a string accepted by the\n[ms](https://www.npmjs.org/package/ms#readme) module.\n\n##### root\n\nServe files relative to `path`.\n\n##### start\n\nByte offset at which the stream starts, defaults to 0. The start is inclusive,\nmeaning `start: 2` will include the 3rd byte in the stream.\n\n#### Events\n\nThe `SendStream` is an event emitter and will emit the following events:\n\n  - `error` an error occurred `(err)`\n  - `directory` a directory was requested `(res, path)`\n  - `file` a file was requested `(path, stat)`\n  - `headers` the headers are about to be set on a file `(res, path, stat)`\n  - `stream` file streaming has started `(stream)`\n  - `end` streaming has completed\n\n#### .pipe\n\nThe `pipe` method is used to pipe the response into the Node.js HTTP response\nobject, typically `send(req, path, options).pipe(res)`.\n\n## Error-handling\n\nBy default when no `error` listeners are present an automatic response will be\nmade, otherwise you have full control over the response, aka you may show a 5xx\npage etc.\n\n## Caching\n\nIt does _not_ perform internal caching, you should use a reverse proxy cache\nsuch as Varnish for this, or those fancy things called CDNs. If your\napplication is small enough that it would benefit from single-node memory\ncaching, it's small enough that it does not need caching at all ;).\n\n## Debugging\n\nTo enable `debug()` instrumentation output export __DEBUG__:\n\n```\n$ DEBUG=send node app\n```\n\n## Running tests\n\n```\n$ npm install\n$ npm test\n```\n\n## Examples\n\n### Serve a specific file\n\nThis simple example will send a specific file to all requests.\n\n```js\nvar http = require('http')\nvar send = require('send')\n\nvar server = http.createServer(function onRequest (req, res) {\n  send(req, '/path/to/index.html')\n    .pipe(res)\n})\n\nserver.listen(3000)\n```\n\n### Serve all files from a directory\n\nThis simple example will just serve up all the files in a\ngiven directory as the top-level. For example, a request\n`GET /foo.txt` will send back `/www/public/foo.txt`.\n\n```js\nvar http = require('http')\nvar parseUrl = require('parseurl')\nvar send = require('send')\n\nvar server = http.createServer(function onRequest (req, res) {\n  send(req, parseUrl(req).pathname, { root: '/www/public' })\n    .pipe(res)\n})\n\nserver.listen(3000)\n```\n\n### Custom file types\n\n```js\nvar extname = require('path').extname\nvar http = require('http')\nvar parseUrl = require('parseurl')\nvar send = require('send')\n\nvar server = http.createServer(function onRequest (req, res) {\n  send(req, parseUrl(req).pathname, { root: '/www/public' })\n    .on('headers', function (res, path) {\n      switch (extname(path)) {\n        case '.x-mt':\n        case '.x-mtt':\n          // custom type for these extensions\n          res.setHeader('Content-Type', 'application/x-my-type')\n          break\n      }\n    })\n    .pipe(res)\n})\n\nserver.listen(3000)\n```\n\n### Custom directory index view\n\nThis is an example of serving up a structure of directories with a\ncustom function to render a listing of a directory.\n\n```js\nvar http = require('http')\nvar fs = require('fs')\nvar parseUrl = require('parseurl')\nvar send = require('send')\n\n// Transfer arbitrary files from within /www/example.com/public/*\n// with a custom handler for directory listing\nvar server = http.createServer(function onRequest (req, res) {\n  send(req, parseUrl(req).pathname, { index: false, root: '/www/public' })\n    .once('directory', directory)\n    .pipe(res)\n})\n\nserver.listen(3000)\n\n// Custom directory handler\nfunction directory (res, path) {\n  var stream = this\n\n  // redirect to trailing slash for consistent url\n  if (!stream.hasTrailingSlash()) {\n    return stream.redirect(path)\n  }\n\n  // get directory list\n  fs.readdir(path, function onReaddir (err, list) {\n    if (err) return stream.error(err)\n\n    // render an index for the directory\n    res.setHeader('Content-Type', 'text/plain; charset=UTF-8')\n    res.end(list.join('\\n') + '\\n')\n  })\n}\n```\n\n### Serving from a root directory with custom error-handling\n\n```js\nvar http = require('http')\nvar parseUrl = require('parseurl')\nvar send = require('send')\n\nvar server = http.createServer(function onRequest (req, res) {\n  // your custom error-handling logic:\n  function error (err) {\n    res.statusCode = err.status || 500\n    res.end(err.message)\n  }\n\n  // your custom headers\n  function headers (res, path, stat) {\n    // serve all files for download\n    res.setHeader('Content-Disposition', 'attachment')\n  }\n\n  // your custom directory handling logic:\n  function redirect () {\n    res.statusCode = 301\n    res.setHeader('Location', req.url + '/')\n    res.end('Redirecting to ' + req.url + '/')\n  }\n\n  // transfer arbitrary files from within\n  // /www/example.com/public/*\n  send(req, parseUrl(req).pathname, { root: '/www/public' })\n    .on('error', error)\n    .on('directory', redirect)\n    .on('headers', headers)\n    .pipe(res)\n})\n\nserver.listen(3000)\n```\n\n## License\n\n[MIT](LICENSE)\n\n[coveralls-image]: https://badgen.net/coveralls/c/github/pillarjs/send/master\n[coveralls-url]: https://coveralls.io/r/pillarjs/send?branch=master\n[github-actions-ci-image]: https://badgen.net/github/checks/pillarjs/send/master?label=linux\n[github-actions-ci-url]: https://github.com/pillarjs/send/actions/workflows/ci.yml\n[node-image]: https://badgen.net/npm/node/send\n[node-url]: https://nodejs.org/en/download/\n[npm-downloads-image]: https://badgen.net/npm/dm/send\n[npm-url]: https://npmjs.org/package/send\n[npm-version-image]: https://badgen.net/npm/v/send\n","publish_time":1765826944515,"_cnpm_publish_time":1765826944515,"dist-tags":{"latest":"1.2.1","latest-0.x":"0.19.2","next":"1.1.0"}}