expressjs / serve-index

Serve directory listings

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Example code doesn't work properly

readyready15728 opened this issue · comments

I followed the advice down at the bottom of README.md more or less, coming up with the following:

'use strict';

const express = require('express');
const serveIndex = require('serve-index');

express()
  .use(serveIndex(__dirname + '/public'))
  .listen(1024);

It lists the files in the directory and formats the results nicely. Bravo. The problem is that, when I click any of those files, it doesn't do what the more laborious example above it in README.md appears to be able do using vanilla Node features. In fact it says Cannot GET /blablabla.

Is there some straightforward, concise way of getting it to function using Express components? Forgive me if I'm not quite thinking this through. In any case, that / those extra step(s) should be added to the example so it works properly.

Yea, sorry, the express example needs to include express.static. I updated the example, which should be what you're looking for :)