Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/404.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在my node.js应用程序中使用express和ejs呈现文件夹内容,如mod_autoindex_Javascript_Node.js_Express - Fatal编程技术网

Javascript 在my node.js应用程序中使用express和ejs呈现文件夹内容,如mod_autoindex

Javascript 在my node.js应用程序中使用express和ejs呈现文件夹内容,如mod_autoindex,javascript,node.js,express,Javascript,Node.js,Express,我一直在使用express和ejs在/public文件夹中呈现原始html文件 例如,要渲染http://localhost:3000/index.html,我有: var express = require('express'); var ejs = require('ejs'); app.engine('.html', ejs.__express); app.set('views', __dirname + '/public'); app.set('view engine', 'htm

我一直在使用express和ejs在
/public
文件夹中呈现原始html文件

例如,要渲染
http://localhost:3000/index.html
,我有:

var express = require('express');
var ejs = require('ejs');

app.engine('.html', ejs.__express);
app.set('views', __dirname + '/public');  
app.set('view engine', 'html');

app.use(express.static(__dirname + './public'));
并且可以呈现来自
/public
的文件:

% find public/
public/index.html
public/favicon.ico
public/stylesheets
public/stylesheets/style.css
public/images
public/images/banner.gif
我希望能够呈现文件夹内容,如
http://localhost:3000/images/
,与Apache模块mod_autoindex完全相同,它是一个文件表,作为显示目录内容的链接


有办法做到这一点吗?

答案很简单,只需搜索npm库

我会做好的