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

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

    The following code will serve both directory and files

    var serveIndex = require('serve-index');
    app.use('/p', serveIndex(path.join(__dirname, 'public')));
    app.use('/p', express.static(path.join(__dirname, 'public')));
    

提交回复
热议问题