{"id":17750567,"url":"https://github.com/nuintun/file-send","last_synced_at":"2025-05-12T19:57:52.095Z","repository":{"id":24298731,"uuid":"27694038","full_name":"nuintun/file-send","owner":"nuintun","description":"A http/https file send","archived":false,"fork":false,"pushed_at":"2024-09-06T07:35:41.000Z","size":1021,"stargazers_count":2,"open_issues_count":14,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-09T17:03:32.074Z","etag":null,"topics":["http","http-server","https","https-server","node-module","server","service"],"latest_commit_sha":null,"homepage":"http://nuintun.github.io/file-send","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nuintun.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-12-08T02:29:06.000Z","updated_at":"2023-03-07T04:21:35.000Z","dependencies_parsed_at":"2024-06-21T15:34:08.569Z","dependency_job_id":"b459276f-0b75-4122-96bd-a92252651114","html_url":"https://github.com/nuintun/file-send","commit_stats":{"total_commits":583,"total_committers":6,"mean_commits":97.16666666666667,"dds":"0.14922813036020588","last_synced_commit":"dc42eb7eb806b41a501270bc0e61ecd08266801b"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuintun%2Ffile-send","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuintun%2Ffile-send/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuintun%2Ffile-send/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuintun%2Ffile-send/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nuintun","download_url":"https://codeload.github.com/nuintun/file-send/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253813942,"owners_count":21968554,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["http","http-server","https","https-server","node-module","server","service"],"created_at":"2024-10-26T12:22:39.857Z","updated_at":"2025-05-12T19:57:52.053Z","avatar_url":"https://github.com/nuintun.png","language":"JavaScript","readme":"# file-send\n\n\u003e A http/https file send\n\u003e\n\u003e [![NPM Version][npm-image]][npm-url]\n\u003e [![Download Status][download-image]][npm-url]\n\u003e [![Linux Status][circleci-image]][circleci-url]\n\u003e [![Windows Status][appveyor-image]][appveyor-url]\n\u003e [![Test Coverage][codecov-image]][codecov-url]\n\u003e ![Node Version][node-image]\n\u003e [![Dependencies][david-image]][david-url]\n\n## Installation\n\n```bash\n$ npm install file-send\n```\n\n## API\n\n```js\nconst url = require('url');\nconst http = require('http');\nconst through2 = require('through2');\nconst FileSend = require('file-send');\n\nhttp.createServer((request, response) =\u003e {\n  new FileSend(request, url.parse(request.url).pathname, {\n    root: '/',\n    etag: true,\n    maxAge: '30d'\n  })\n    .on('dir', function(realpath, next) {\n      // dir events\n      next('dir');\n    })\n    .on('error', function(error, next) {\n      // error events\n      next('error');\n    })\n    .use(through2()) // Set middleware\n    .pipe(response); // Send file to response\n});\n```\n\n### FileSend(request, path, [options])\n\nCreate a new `FileSend` for the given path and options to initialize.\nThe `request` is the Node.js HTTP request and the `path` is a urlencoded path to send (urlencoded, not the actual file-system path).\n\n#### Options\n\n##### _root_ - `String`\n\nSet server root.\n\n##### _ignore_ - `String|Array`\n\nSet ignore rules, support glob string. see: [micromatch](https://github.com/jonschlinkert/micromatch)\n\n##### _ignoreAccess_ - `String`\n\nSet how \"ignore\" are treated when encountered.\n\nThe default value is `'deny'`.\n\n- `'deny'` Send a 403 for any request for ignore matched.\n- `'ignore'` Pretend like the ignore matched does not exist and 404.\n\n##### _glob_ - `Object`\n\nSet micromatch options. see: [micromatch](https://github.com/jonschlinkert/micromatch#options)\n\n#### _acceptRanges_ - `Boolean`\n\nEnable or disable accepting ranged requests, defaults to true. Disabling this will not send Accept-Ranges and ignore the contents of the Range request header.\n\n##### _charset_ - `String`\n\nSet Content-Type charset.\n\n##### _cacheControl_ - `Boolean`\n\nEnable or disable setting `Cache-Control` response header, defaults to true. Disabling this will ignore the `immutable` and `maxAge` options.\n\n##### _etag_ - `Boolean`\n\nEnable or disable etag generation, defaults to true.\n\n##### _index_ - `String|Array|Boolean`\n\nBy default send supports \"index.html\" files, to disable this set `false` or to supply a new index pass a string or an array in preferred order.\n\n##### _lastModified_ - `Boolean`\n\nEnable or disable `Last-Modified` header, defaults to true. Uses the file system's last modified value.\n\n##### _maxAge_ - `String|Number`\n\nProvide a max-age in milliseconds for http caching, defaults to 0.\nThis can also be a string accepted by the [ms](https://www.npmjs.org/package/ms#readme) module.\n\n##### _immutable_ - `Boolean`\n\nEnable or diable the immutable directive in the Cache-Control response header, defaults to false. If set to true, the maxAge option should also be specified to enable caching. The immutable directive will prevent supported clients from making conditional requests during the life of the maxAge option to check if the file has changed.\n\n### FileSend(request, path, [options]).pipe(response)\n\nThe `pipe` method is used to pipe the response into the Node.js HTTP response object, typically `FileSend(request, path, [options]).pipe(response)`.\n\n### FileSend.mime\n\nThe mime export is the global instance of of the `mime-types` npm module.\n\n### Events\n\nThe `FileSend` is an event emitter and will emit the following events:\n\n- `dir` a directory was requested`(realpath, next)`\n- `file` a file was requested `(realpath, stats)`\n- `error` an error occurred `(error, next)`\n\n## Error-handling\n\nBy default when no `error` listeners are present an automatic response will be made, otherwise you have full control over the response, aka you may show a 5xx page etc.\n\n## Caching\n\nIt does _not_ perform internal caching, you should use a reverse proxy cache such as Varnish for this, or those fancy things called CDNs. If your application is small enough that it would benefit from single-node memory caching, it's small enough that it does not need caching at all ;).\n\n## Running tests\n\n```\n$ npm install\n$ npm test\n```\n\n## Examples\n\n```js\n'use strict';\n\nconst url = require('url');\nconst http = require('http');\nconst chalk = require('chalk');\nconst cluster = require('cluster');\nconst FileSend = require('file-send');\nconst NUMCPUS = require('os').cpus().length;\n\n// create server\nfunction createServer(root, port) {\n  http\n    .createServer(function(request, response) {\n      const send = new FileSend(request, url.parse(request.url).pathname, {\n        root: root || process.cwd(),\n        maxAge: '3day',\n        index: ['index.html'],\n        ignore: ['**/.*?(/**)']\n      });\n\n      send.pipe(response);\n    })\n    .listen(port || 8080);\n}\n\nif (cluster.isMaster) {\n  // fork workers\n  for (let i = 0; i \u003c NUMCPUS; i++) {\n    const worker = cluster.fork();\n\n    // worker is listening\n    if (i === NUMCPUS - 1) {\n      worker.on('listening', address =\u003e {\n        console.log(\n          chalk.green.bold('Server run at:'),\n          chalk.cyan.bold((address.address || '127.0.0.1') + ':' + address.port),\n          '\\r\\n-----------------------------------------------------------------------------------------'\n        );\n      });\n    }\n  }\n} else {\n  // workers can share any tcp connection\n  // in this case it is an http server\n  createServer();\n}\n```\n\n## License\n\n[MIT](LICENSE)\n\n[circleci-image]: https://img.shields.io/circleci/project/github/nuintun/file-send.svg?style=flat-square\u0026label=linux\n[circleci-url]: https://circleci.com/gh/nuintun/file-send\n[appveyor-image]: https://img.shields.io/appveyor/ci/nuintun/file-send/master.svg?style=flat-square\u0026label=windows\n[appveyor-url]: https://ci.appveyor.com/project/nuintun/file-send\n[codecov-image]: https://img.shields.io/codecov/c/github/nuintun/file-send.svg?style=flat-square\n[codecov-url]: https://codecov.io/gh/nuintun/file-send\n[node-image]: https://img.shields.io/node/v/file-send.svg?style=flat-square\n[david-image]: https://img.shields.io/david/nuintun/file-send.svg?style=flat-square\n[david-url]: https://david-dm.org/nuintun/file-send\n[npm-image]: https://img.shields.io/npm/v/file-send.svg?style=flat-square\n[npm-url]: https://www.npmjs.org/package/file-send\n[download-image]: https://img.shields.io/npm/dm/file-send.svg?style=flat-square\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnuintun%2Ffile-send","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnuintun%2Ffile-send","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnuintun%2Ffile-send/lists"}