source: trip-planner-front/node_modules/serve-index/README.md@ 6c1585f

Last change on this file since 6c1585f was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 5.0 KB
Line 
1# serve-index
2
3[![NPM Version][npm-image]][npm-url]
4[![NPM Downloads][downloads-image]][downloads-url]
5[![Linux Build][travis-image]][travis-url]
6[![Windows Build][appveyor-image]][appveyor-url]
7[![Test Coverage][coveralls-image]][coveralls-url]
8[![Gratipay][gratipay-image]][gratipay-url]
9
10 Serves pages that contain directory listings for a given path.
11
12## Install
13
14This is a [Node.js](https://nodejs.org/en/) module available through the
15[npm registry](https://www.npmjs.com/). Installation is done using the
16[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
17
18```sh
19$ npm install serve-index
20```
21
22## API
23
24```js
25var serveIndex = require('serve-index')
26```
27
28### serveIndex(path, options)
29
30Returns middlware that serves an index of the directory in the given `path`.
31
32The `path` is based off the `req.url` value, so a `req.url` of `'/some/dir`
33with a `path` of `'public'` will look at `'public/some/dir'`. If you are using
34something like `express`, you can change the URL "base" with `app.use` (see
35the express example).
36
37#### Options
38
39Serve index accepts these properties in the options object.
40
41##### filter
42
43Apply this filter function to files. Defaults to `false`. The `filter` function
44is called for each file, with the signature `filter(filename, index, files, dir)`
45where `filename` is the name of the file, `index` is the array index, `files` is
46the array of files and `dir` is the absolute path the file is located (and thus,
47the directory the listing is for).
48
49##### hidden
50
51Display hidden (dot) files. Defaults to `false`.
52
53##### icons
54
55Display icons. Defaults to `false`.
56
57##### stylesheet
58
59Optional path to a CSS stylesheet. Defaults to a built-in stylesheet.
60
61##### template
62
63Optional path to an HTML template or a function that will render a HTML
64string. Defaults to a built-in template.
65
66When given a string, the string is used as a file path to load and then the
67following tokens are replaced in templates:
68
69 * `{directory}` with the name of the directory.
70 * `{files}` with the HTML of an unordered list of file links.
71 * `{linked-path}` with the HTML of a link to the directory.
72 * `{style}` with the specified stylesheet and embedded images.
73
74When given as a function, the function is called as `template(locals, callback)`
75and it needs to invoke `callback(error, htmlString)`. The following are the
76provided locals:
77
78 * `directory` is the directory being displayed (where `/` is the root).
79 * `displayIcons` is a Boolean for if icons should be rendered or not.
80 * `fileList` is a sorted array of files in the directory. The array contains
81 objects with the following properties:
82 - `name` is the relative name for the file.
83 - `stat` is a `fs.Stats` object for the file.
84 * `path` is the full filesystem path to `directory`.
85 * `style` is the default stylesheet or the contents of the `stylesheet` option.
86 * `viewName` is the view name provided by the `view` option.
87
88##### view
89
90Display mode. `tiles` and `details` are available. Defaults to `tiles`.
91
92## Examples
93
94### Serve directory indexes with vanilla node.js http server
95
96```js
97var finalhandler = require('finalhandler')
98var http = require('http')
99var serveIndex = require('serve-index')
100var serveStatic = require('serve-static')
101
102// Serve directory indexes for public/ftp folder (with icons)
103var index = serveIndex('public/ftp', {'icons': true})
104
105// Serve up public/ftp folder files
106var serve = serveStatic('public/ftp')
107
108// Create server
109var server = http.createServer(function onRequest(req, res){
110 var done = finalhandler(req, res)
111 serve(req, res, function onNext(err) {
112 if (err) return done(err)
113 index(req, res, done)
114 })
115})
116
117// Listen
118server.listen(3000)
119```
120
121### Serve directory indexes with express
122
123```js
124var express = require('express')
125var serveIndex = require('serve-index')
126
127var app = express()
128
129// Serve URLs like /ftp/thing as public/ftp/thing
130// The express.static serves the file contents
131// The serveIndex is this module serving the directory
132app.use('/ftp', express.static('public/ftp'), serveIndex('public/ftp', {'icons': true}))
133
134// Listen
135app.listen(3000)
136```
137
138## License
139
140[MIT](LICENSE). The [Silk](http://www.famfamfam.com/lab/icons/silk/) icons
141are created by/copyright of [FAMFAMFAM](http://www.famfamfam.com/).
142
143[npm-image]: https://img.shields.io/npm/v/serve-index.svg
144[npm-url]: https://npmjs.org/package/serve-index
145[travis-image]: https://img.shields.io/travis/expressjs/serve-index/master.svg?label=linux
146[travis-url]: https://travis-ci.org/expressjs/serve-index
147[appveyor-image]: https://img.shields.io/appveyor/ci/dougwilson/serve-index/master.svg?label=windows
148[appveyor-url]: https://ci.appveyor.com/project/dougwilson/serve-index
149[coveralls-image]: https://img.shields.io/coveralls/expressjs/serve-index/master.svg
150[coveralls-url]: https://coveralls.io/r/expressjs/serve-index?branch=master
151[downloads-image]: https://img.shields.io/npm/dm/serve-index.svg
152[downloads-url]: https://npmjs.org/package/serve-index
153[gratipay-image]: https://img.shields.io/gratipay/dougwilson.svg
154[gratipay-url]: https://www.gratipay.com/dougwilson/
Note: See TracBrowser for help on using the repository browser.