Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Serve directory listings

License

NotificationsYou must be signed in to change notification settings

expressjs/serve-index

NPM VersionNPM DownloadsLinux Build StatusWindows BuildCoverage Status

Serves pages that contain directory listings for a given path.

Install

This is aNode.js module available through thenpm registry. Installation is done using thenpm install command:

$ npm install serve-index

API

varserveIndex=require('serve-index')

serveIndex(path, options)

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).

Options

Serve index accepts these properties in the options object.

filter

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).

hidden

Display hidden (dot) files. Defaults tofalse.

icons

Display icons. Defaults tofalse.

stylesheet

Optional path to a CSS stylesheet. Defaults to a built-in stylesheet.

template

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:

  • directory is the directory being displayed (where/ is the root).
  • displayIcons is a Boolean for if icons should be rendered or not.
  • fileList is a sorted array of files in the directory. The array containsobjects with the following properties:
    • name is the relative name for the file.
    • stat is afs.Stats object for the file.
  • path is the full filesystem path todirectory.
  • style is the default stylesheet or the contents of thestylesheet option.
  • viewName is the view name provided by theview option.
view

Display mode.tiles anddetails are available. Defaults totiles.

Examples

Serve directory indexes with vanilla node.js http server

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)

Serve directory indexes with express

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)

License

MIT. TheSilk iconsare created by/copyright ofFAMFAMFAM.

About

Serve directory listings

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

    Packages

    No packages published

    Contributors18


    [8]ページ先頭

    ©2009-2025 Movatter.jp