\href{https://npmjs.org/package/serve-index}{\texttt{ }} \href{https://npmjs.org/package/serve-index}{\texttt{ }} \href{https://travis-ci.org/expressjs/serve-index}{\texttt{ }} \href{https://ci.appveyor.com/project/dougwilson/serve-index}{\texttt{ }} \href{https://coveralls.io/r/expressjs/serve-index?branch=master}{\texttt{ }} \href{https://www.gratipay.com/dougwilson/}{\texttt{ }}

Serves pages that contain directory listings for a given path.\hypertarget{md_sfcode_node_modules_serve_index_README_autotoc_md26863}{}\doxysection{Install}\label{md_sfcode_node_modules_serve_index_README_autotoc_md26863}
This is a \href{https://nodejs.org/en/}{\texttt{ Node.\+js}} module available through the \href{https://www.npmjs.com/}{\texttt{ npm registry}}. Installation is done using the \href{https://docs.npmjs.com/getting-started/installing-npm-packages-locally}{\texttt{ {\ttfamily npm install} command}}\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\$ npm install serve-\/index }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_serve_index_README_autotoc_md26864}{}\doxysection{API}\label{md_sfcode_node_modules_serve_index_README_autotoc_md26864}

\begin{DoxyCode}{0}
\DoxyCodeLine{var serveIndex = require('serve-\/index') }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_serve_index_README_autotoc_md26865}{}\doxysubsection{serve\+Index(path, options)}\label{md_sfcode_node_modules_serve_index_README_autotoc_md26865}
Returns middlware that serves an index of the directory in the given {\ttfamily path}.

The {\ttfamily path} is based off the {\ttfamily req.\+url} value, so a {\ttfamily req.\+url} of `'/some/dir{\ttfamily  with a}path{\ttfamily of}\textquotesingle{}public\textquotesingle{}{\ttfamily will look at}\textquotesingle{}public/some/dir\textquotesingle{}{\ttfamily . If you are using something like}express{\ttfamily , you can change the URL \char`\"{}base\char`\"{} with}app.\+use\`{} (see the express example).\hypertarget{md_sfcode_node_modules_serve_index_README_autotoc_md26866}{}\doxysubsubsection{Options}\label{md_sfcode_node_modules_serve_index_README_autotoc_md26866}
Serve index accepts these properties in the options object.\hypertarget{md_sfcode_node_modules_serve_index_README_autotoc_md26867}{}\doxyparagraph{filter}\label{md_sfcode_node_modules_serve_index_README_autotoc_md26867}
Apply this filter function to files. Defaults to {\ttfamily false}. The {\ttfamily filter} function is called for each file, with the signature {\ttfamily filter(filename, index, files, dir)} where {\ttfamily filename} is the name of the file, {\ttfamily index} is the array index, {\ttfamily files} is the array of files and {\ttfamily dir} is the absolute path the file is located (and thus, the directory the listing is for).\hypertarget{md_sfcode_node_modules_serve_index_README_autotoc_md26868}{}\doxyparagraph{hidden}\label{md_sfcode_node_modules_serve_index_README_autotoc_md26868}
Display hidden (dot) files. Defaults to {\ttfamily false}.\hypertarget{md_sfcode_node_modules_serve_index_README_autotoc_md26869}{}\doxyparagraph{icons}\label{md_sfcode_node_modules_serve_index_README_autotoc_md26869}
Display icons. Defaults to {\ttfamily false}.\hypertarget{md_sfcode_node_modules_serve_index_README_autotoc_md26870}{}\doxyparagraph{stylesheet}\label{md_sfcode_node_modules_serve_index_README_autotoc_md26870}
Optional path to a CSS stylesheet. Defaults to a built-\/in stylesheet.\hypertarget{md_sfcode_node_modules_serve_index_README_autotoc_md26871}{}\doxyparagraph{template}\label{md_sfcode_node_modules_serve_index_README_autotoc_md26871}
Optional path to an HTML template or a function that will render a HTML string. Defaults to a built-\/in template.

When given a string, the string is used as a file path to load and then the following tokens are replaced in templates\+:


\begin{DoxyItemize}
\item {\ttfamily \{directory\}} with the name of the directory.
\item {\ttfamily \{files\}} with the HTML of an unordered list of file links.
\item {\ttfamily \{linked-\/path\}} with the HTML of a link to the directory.
\item {\ttfamily \{style\}} with the specified stylesheet and embedded images.
\end{DoxyItemize}

When given as a function, the function is called as {\ttfamily template(locals, callback)} and it needs to invoke {\ttfamily callback(error, html\+String)}. The following are the provided locals\+:


\begin{DoxyItemize}
\item {\ttfamily directory} is the directory being displayed (where {\ttfamily /} is the root).
\item {\ttfamily display\+Icons} is a Boolean for if icons should be rendered or not.
\item {\ttfamily file\+List} is a sorted array of files in the directory. The array contains objects with the following properties\+:
\begin{DoxyItemize}
\item {\ttfamily name} is the relative name for the file.
\item {\ttfamily stat} is a {\ttfamily fs.\+Stats} object for the file.
\end{DoxyItemize}
\item {\ttfamily path} is the full filesystem path to {\ttfamily directory}.
\item {\ttfamily style} is the default stylesheet or the contents of the {\ttfamily stylesheet} option.
\item {\ttfamily view\+Name} is the view name provided by the {\ttfamily view} option.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_serve_index_README_autotoc_md26872}{}\doxyparagraph{view}\label{md_sfcode_node_modules_serve_index_README_autotoc_md26872}
Display mode. {\ttfamily tiles} and {\ttfamily details} are available. Defaults to {\ttfamily tiles}.\hypertarget{md_sfcode_node_modules_serve_index_README_autotoc_md26873}{}\doxysection{Examples}\label{md_sfcode_node_modules_serve_index_README_autotoc_md26873}
\hypertarget{md_sfcode_node_modules_serve_index_README_autotoc_md26874}{}\doxysubsection{Serve directory indexes with vanilla node.\+js http server}\label{md_sfcode_node_modules_serve_index_README_autotoc_md26874}

\begin{DoxyCode}{0}
\DoxyCodeLine{var finalhandler = require('finalhandler')}
\DoxyCodeLine{var http = require('http')}
\DoxyCodeLine{var serveIndex = require('serve-\/index')}
\DoxyCodeLine{var serveStatic = require('serve-\/static')}
\DoxyCodeLine{}
\DoxyCodeLine{// Serve directory indexes for public/ftp folder (with icons)}
\DoxyCodeLine{var index = serveIndex('public/ftp', \{'icons': true\})}
\DoxyCodeLine{}
\DoxyCodeLine{// Serve up public/ftp folder files}
\DoxyCodeLine{var serve = serveStatic('public/ftp')}
\DoxyCodeLine{}
\DoxyCodeLine{// Create server}
\DoxyCodeLine{var server = http.createServer(function onRequest(req, res)\{}
\DoxyCodeLine{  var done = finalhandler(req, res)}
\DoxyCodeLine{  serve(req, res, function onNext(err) \{}
\DoxyCodeLine{    if (err) return done(err)}
\DoxyCodeLine{    index(req, res, done)}
\DoxyCodeLine{  \})}
\DoxyCodeLine{\})}
\DoxyCodeLine{}
\DoxyCodeLine{// Listen}
\DoxyCodeLine{server.listen(3000) }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_serve_index_README_autotoc_md26875}{}\doxysubsection{Serve directory indexes with express}\label{md_sfcode_node_modules_serve_index_README_autotoc_md26875}

\begin{DoxyCode}{0}
\DoxyCodeLine{var express    = require('express')}
\DoxyCodeLine{var serveIndex = require('serve-\/index')}
\DoxyCodeLine{}
\DoxyCodeLine{var app = express()}
\DoxyCodeLine{}
\DoxyCodeLine{// Serve URLs like /ftp/thing as public/ftp/thing}
\DoxyCodeLine{// The express.static serves the file contents}
\DoxyCodeLine{// The serveIndex is this module serving the directory}
\DoxyCodeLine{app.use('/ftp', express.static('public/ftp'), serveIndex('public/ftp', \{'icons': true\}))}
\DoxyCodeLine{}
\DoxyCodeLine{// Listen}
\DoxyCodeLine{app.listen(3000) }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_serve_index_README_autotoc_md26876}{}\doxysection{License}\label{md_sfcode_node_modules_serve_index_README_autotoc_md26876}
\mbox{[}MIT\mbox{]}(LICENSE). The \href{http://www.famfamfam.com/lab/icons/silk/}{\texttt{ Silk}} icons are created by/copyright of \href{http://www.famfamfam.com/}{\texttt{ FAMFAMFAM}}. 