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

前端 未结 5 1346
故里飘歌
故里飘歌 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:51

    This will do the work for you: (new version of express requires separate middleware). E.g. you put your files under folder 'files' and you want the url to be '/public'

    var express = require('express');
    var serveIndex = require('serve-index');
    var app = express();
    
    app.use('/public', serveIndex('files')); // shows you the file list
    app.use('/public', express.static('files')); // serve the actual files
    

提交回复
热议问题