Express.js - any way to display a file/dir listing?

前端 未结 5 1347
故里飘歌
故里飘歌 2020-12-02 14:33

With Express.js is there a way to display a file/dir listing like apache does when you access the URL of a directory which doesn\'t have a index file - so it displays a list

5条回答
  •  感情败类
    2020-12-02 14:41

    There's a brand new default Connect middleware named directory (source) for directory listings. It has a lot of style and has a client-side search box.

    var express = require('express')
      , app = express.createServer();
    
    app.configure(function() {
      var hourMs = 1000*60*60;
      app.use(express.static(__dirname + '/public', { maxAge: hourMs }));
      app.use(express.directory(__dirname + '/public'));
      app.use(express.errorHandler());
    });
    
    app.listen(8080);
    

提交回复
热议问题