{"id":14957514,"url":"https://github.com/expressjs/serve-index","last_synced_at":"2025-05-13T19:05:00.265Z","repository":{"id":14738140,"uuid":"17459063","full_name":"expressjs/serve-index","owner":"expressjs","description":"Serve directory listings","archived":false,"fork":false,"pushed_at":"2025-04-17T14:17:01.000Z","size":289,"stargazers_count":444,"open_issues_count":30,"forks_count":152,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-04-25T21:52:41.703Z","etag":null,"topics":["directory","expressjs","index","javascript","middleware","nodejs"],"latest_commit_sha":null,"homepage":null,"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/expressjs.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","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,"zenodo":null},"funding":{"open_collective":"express"}},"created_at":"2014-03-05T23:26:46.000Z","updated_at":"2025-04-25T09:57:20.000Z","dependencies_parsed_at":"2024-09-27T03:10:53.778Z","dependency_job_id":"54202c51-9149-4dc6-b32d-5027d16fce9f","html_url":"https://github.com/expressjs/serve-index","commit_stats":{"total_commits":386,"total_committers":14,"mean_commits":"27.571428571428573","dds":"0.041450777202072575","last_synced_commit":"544279a0642a541f385a30d402374565bf6b147b"},"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/expressjs%2Fserve-index","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/expressjs%2Fserve-index/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/expressjs%2Fserve-index/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/expressjs%2Fserve-index/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/expressjs","download_url":"https://codeload.github.com/expressjs/serve-index/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250983823,"owners_count":21518024,"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":["directory","expressjs","index","javascript","middleware","nodejs"],"created_at":"2024-09-24T13:15:01.467Z","updated_at":"2025-04-27T04:40:54.531Z","avatar_url":"https://github.com/expressjs.png","language":"JavaScript","readme":"# serve-index\n\n[![NPM Version][npm-image]][npm-url]\n[![NPM Downloads][downloads-image]][downloads-url]\n[![Linux Build Status][ci-image]][ci-url]\n[![Windows Build][appveyor-image]][appveyor-url]\n[![Coverage Status][coveralls-image]][coveralls-url]\n\n  Serves pages that contain directory listings for a given path.\n\n## Install\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```sh\n$ npm install serve-index\n```\n\n## API\n\n```js\nvar serveIndex = require('serve-index')\n```\n\n### serveIndex(path, options)\n\nReturns middlware that serves an index of the directory in the given `path`.\n\nThe `path` is based off the `req.url` value, so a `req.url` of `'/some/dir`\nwith a `path` of `'public'` will look at `'public/some/dir'`. If you are using\nsomething like `express`, you can change the URL \"base\" with `app.use` (see\nthe express example).\n\n#### Options\n\nServe index accepts these properties in the options object.\n\n##### filter\n\nApply this filter function to files. Defaults to `false`. The `filter` function\nis called for each file, with the signature `filter(filename, index, files, dir)`\nwhere `filename` is the name of the file, `index` is the array index, `files` is\nthe array of files and `dir` is the absolute path the file is located (and thus,\nthe directory the listing is for).\n\n##### hidden\n\nDisplay hidden (dot) files. Defaults to `false`.\n\n##### icons\n\nDisplay icons. Defaults to `false`.\n\n##### stylesheet\n\nOptional path to a CSS stylesheet. Defaults to a built-in stylesheet.\n\n##### template\n\nOptional path to an HTML template or a function that will render a HTML\nstring. Defaults to a built-in template.\n\nWhen given a string, the string is used as a file path to load and then the\nfollowing tokens are replaced in templates:\n\n  * `{directory}` with the name of the directory.\n  * `{files}` with the HTML of an unordered list of file links.\n  * `{linked-path}` with the HTML of a link to the directory.\n  * `{style}` with the specified stylesheet and embedded images.\n\nWhen given as a function, the function is called as `template(locals, callback)`\nand it needs to invoke `callback(error, htmlString)`. The following are the\nprovided locals:\n\n  * `directory` is the directory being displayed (where `/` is the root).\n  * `displayIcons` is a Boolean for if icons should be rendered or not.\n  * `fileList` is a sorted array of files in the directory. The array contains\n    objects with the following properties:\n    - `name` is the relative name for the file.\n    - `stat` is a `fs.Stats` object for the file.\n  * `path` is the full filesystem path to `directory`.\n  * `style` is the default stylesheet or the contents of the `stylesheet` option.\n  * `viewName` is the view name provided by the `view` option.\n\n##### view\n\nDisplay mode. `tiles` and `details` are available. Defaults to `tiles`.\n\n## Examples\n\n### Serve directory indexes with vanilla node.js http server\n\n```js\nvar finalhandler = require('finalhandler')\nvar http = require('http')\nvar serveIndex = require('serve-index')\nvar serveStatic = require('serve-static')\n\n// Serve directory indexes for public/ftp folder (with icons)\nvar index = serveIndex('public/ftp', {'icons': true})\n\n// Serve up public/ftp folder files\nvar serve = serveStatic('public/ftp')\n\n// Create server\nvar server = http.createServer(function onRequest(req, res){\n  var done = finalhandler(req, res)\n  serve(req, res, function onNext(err) {\n    if (err) return done(err)\n    index(req, res, done)\n  })\n})\n\n// Listen\nserver.listen(3000)\n```\n\n### Serve directory indexes with express\n\n```js\nvar express    = require('express')\nvar serveIndex = require('serve-index')\n\nvar app = express()\n\n// Serve URLs like /ftp/thing as public/ftp/thing\n// The express.static serves the file contents\n// The serveIndex is this module serving the directory\napp.use('/ftp', express.static('public/ftp'), serveIndex('public/ftp', {'icons': true}))\n\n// Listen\napp.listen(3000)\n```\n\n## License\n\n[MIT](LICENSE). The [Silk](http://www.famfamfam.com/lab/icons/silk/) icons\nare created by/copyright of [FAMFAMFAM](http://www.famfamfam.com/).\n\n[appveyor-image]: https://img.shields.io/appveyor/ci/dougwilson/serve-index/master.svg?label=windows\n[appveyor-url]: https://ci.appveyor.com/project/dougwilson/serve-index\n[ci-image]: https://badgen.net/github/checks/expressjs/serve-index/master?label=ci\n[ci-url]: https://github.com/expressjs/serve-index/actions/workflows/ci.yml\n[coveralls-image]: https://img.shields.io/coveralls/expressjs/serve-index/master.svg\n[coveralls-url]: https://coveralls.io/r/expressjs/serve-index?branch=master\n[downloads-image]: https://img.shields.io/npm/dm/serve-index.svg\n[downloads-url]: https://npmjs.org/package/serve-index\n[npm-image]: https://img.shields.io/npm/v/serve-index.svg\n[npm-url]: https://npmjs.org/package/serve-index","funding_links":["https://opencollective.com/express"],"categories":["JavaScript","中间件"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexpressjs%2Fserve-index","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexpressjs%2Fserve-index","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexpressjs%2Fserve-index/lists"}