Giter Site home page Giter Site logo

directory-index-html's Introduction

directory-index-html

Make an plain html page containing a directory listing. Similar in look and feel to NGINX's listing page.

npm install directory-index-html

Usage

var toHTML = require('directory-index-html')

var entries = [{
  name: 'test',
  size: 24424,
  mtime: new Date()
}, {
  name: 'a-dir/',
  mtime: new Date()
}]

console.log(toHTML('/foo/bar', entries))

API

var html = toHTML(dir, entries)

Render a directory name and listing to an plain HTML string.

dir should be a string containing the directory name.

entries should be an array of entries that are similar to this

{
  name: 'name-of-file-or-dir',
  size: 42424, // size in bytes
  mtime: new Date() // when was this modified
}

To figure out if an entry is a directory the module will one of the following things:

  • Check if the path ends with a /
  • See if entry.type === 'directory'
  • See if entry.mode specifies a directory

Demo

There is a small demo server bundled in the repo that serves a directory listing of your current working directory.

To try it out, run node demo.js and visit http://localhost:8080.

It should show something like this:

demo.png

License

MIT

directory-index-html's People

Contributors

mafintosh avatar

Stargazers

 avatar notfire avatar Jörgen Gullstrand  avatar  avatar Ethan Brown avatar Cat  avatar Sheldon Rupp avatar Justin Woodward avatar Bent Cardan avatar Sayan Naskar avatar Jerzerak avatar Dan Bennett avatar Joe Hand avatar Michal Skuza avatar Isao Yagi avatar Gokhan avatar Robert Audi avatar Dominik Deobald avatar coderaiser avatar Simon Kusterer avatar Marcus André avatar Zhao Xiaohong avatar Lsong avatar Athan avatar Julian Gruber avatar Dylan Koji-Cheslin avatar Martin van Driel avatar Azer Koçulu avatar Jake Burden avatar Yosh avatar Emil Bay avatar Thomas Watson avatar  avatar

Watchers

 avatar James Cloos avatar  avatar  avatar

Forkers

joehand

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.