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

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

    As of Express 4.x, the directory middleware is no longer bundled with express. You'll want to download the npm module serve-index.

    Then, for example, to display the file/dir listings in a directory at the root of the app called videos would look like:

        var serveIndex = require('serve-index');
    
        app.use(express.static(__dirname + "/"))
        app.use('/videos', serveIndex(__dirname + '/videos'));
    

提交回复
热议问题