Express.js - 显示文件/目录列表的任何方式? [英] Express.js - any way to display a file/dir listing?

查看:236
本文介绍了Express.js - 显示文件/目录列表的任何方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Express.js 可以在访问URL时显示文件/目录列表(如apache)的目录没有索引文件 - 所以它显示所有目录内容的列表?

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 listing of all that directories contents?

有没有扩展或包,这样做,我don不知道?或者我必须自己编码?

Is there an extension or package that does this which I don't know of? Or will I have to code this myself?

欢呼们,你摇滚! :)

Cheers guys, you rock! :)

推荐答案

有一个全新的默认设置连接名为目录的中间件 资源)用于目录列表。它有很多风格,并有一个客户端搜索框。

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);

这篇关于Express.js - 显示文件/目录列表的任何方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆