Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork156
expressjs/serve-index
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Serves pages that contain directory listings for a given path.
This is aNode.js module available through thenpm registry. Installation is done using thenpm install command:
$ npm install serve-index
varserveIndex=require('serve-index')
Returns middlware that serves an index of the directory in the givenpath.
Thepath is based off thereq.url value, so areq.url of'/some/dirwith apath of'public' will look at'public/some/dir'. If you are usingsomething likeexpress, you can change the URL "base" withapp.use (seethe express example).
Serve index accepts these properties in the options object.
Apply this filter function to files. Defaults tofalse. Thefilter functionis called for each file, with the signaturefilter(filename, index, files, dir)wherefilename is the name of the file,index is the array index,files isthe array of files anddir is the absolute path the file is located (and thus,the directory the listing is for).
Display hidden (dot) files. Defaults tofalse.
Display icons. Defaults tofalse.
Optional path to a CSS stylesheet. Defaults to a built-in stylesheet.
Optional path to an HTML template or a function that will render a HTMLstring. Defaults to a built-in template.
When given a string, the string is used as a file path to load and then thefollowing tokens are replaced in templates:
{directory}with the name of the directory.{files}with the HTML of an unordered list of file links.{linked-path}with the HTML of a link to the directory.{style}with the specified stylesheet and embedded images.
When given as a function, the function is called astemplate(locals, callback)and it needs to invokecallback(error, htmlString). The following are theprovided locals:
directoryis the directory being displayed (where/is the root).displayIconsis a Boolean for if icons should be rendered or not.fileListis a sorted array of files in the directory. The array containsobjects with the following properties:nameis the relative name for the file.statis afs.Statsobject for the file.
pathis the full filesystem path todirectory.styleis the default stylesheet or the contents of thestylesheetoption.viewNameis the view name provided by theviewoption.
Display mode.tiles anddetails are available. Defaults totiles.
varfinalhandler=require('finalhandler')varhttp=require('http')varserveIndex=require('serve-index')varserveStatic=require('serve-static')// Serve directory indexes for public/ftp folder (with icons)varindex=serveIndex('public/ftp',{'icons':true})// Serve up public/ftp folder filesvarserve=serveStatic('public/ftp')// Create servervarserver=http.createServer(functiononRequest(req,res){vardone=finalhandler(req,res)serve(req,res,functiononNext(err){if(err)returndone(err)index(req,res,done)})})// Listenserver.listen(3000)
varexpress=require('express')varserveIndex=require('serve-index')varapp=express()// Serve URLs like /ftp/thing as public/ftp/thing// The express.static serves the file contents// The serveIndex is this module serving the directoryapp.use('/ftp',express.static('public/ftp'),serveIndex('public/ftp',{'icons':true}))// Listenapp.listen(3000)
About
Serve directory listings
Topics
Resources
License
Code of conduct
Contributing
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.