serve-directory v5.0.0
serve-directory
Serves pages that contain directory listings for a given path. forked from expressjs/serve-directory
Installation
yarn add serve-directoryUsage
import serveDirectory from 'serve-directory'
const directory = serveDirectory('wwwroot', options)Serve directory indexes with vanilla node.js http server
see example.js
serveDirectory(path, options)
Returns middleware that serves an index of the directory in the given path.
The path is based off the req.url value, so a req.url of '/some/dir
with a path of 'public' will look at 'public/some/dir'. If you are using
something like express, you can change the URL "base" with app.use (see
the express example).
options(Object)
serveDirectory accepts these properties in the options object.
example
{
imports: {},
hidden: false,
relative: true,
process: [
{
accept: 'text/html',
render: 'lib/directory.jst'
},
{
accept: 'text/plain',
render: ({fileNames}) => fileNames.join(EOL) + EOL,
},
{
accept: 'application/json',
render: ({fileNames}) => JSON.stringify(fileNames),
},
]
}options.imports(Object)
An object to import into the template as free variables., see lodash.template
by default some useful functions will import automatically
see utils/index.js
options.hidden(Boolean)
Show hidden files(file/folder start with .) , defaults to false.
options.relative(Object)
Use relative url , default true.
options.process(Array)
Array list how data should be handled
options.accept
Array or String split with ,
space will be trim
options.render
by default we use a compiled lodash.template function to render data
see lodash.template
Stringa path to a template file a template string
Functiona custom render function
falsyvalueremove default render function
data
data pass to the render function
path
Stringphysical path
pathname
Stringdecoded request pathname
url
URLrequest URL object
method
Stringrequest method
responseType
Stringresponse mine-type / content-type
directory
fs.Statsdirectory stats with additional info
pathpathnameurlfiles
Array<fs.Stats>directory files stats with additional info
nameexttypeurlfileNames
Array<String>directory files but
nameonly
License
MIT © fisker Cheung
4 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago