是否有Node.js即用工具(与npm一起安装),可以帮助我通过HTTP将文件夹内容作为文件服务器公开。

例如,如果我有

D:\Folder\file.zip
D:\Folder\file2.html
D:\Folder\folder\file-in-folder.jpg

然后从D:\Folder\node node-file-server.js开始我可以通过

http://hostname/file.zip
http://hostname/file2.html
http://hostname/folder/file-in-folder.jpg

为什么我的节点静态文件服务器丢弃请求?参考一些神秘的

标准node.js静态文件服务器

如果没有这样的工具,我应该使用什么框架?

相关:NodeJS中的基本静态文件服务器


当前回答

对于开发工作,您可以使用(express 4)https://github.com/appsmatics/simple-httpserver.git

其他回答

您还问了为什么请求会下降-不确定具体原因是什么,但总体而言,您可以使用专用中间件(nginx、S3、CDN)更好地服务静态内容,因为Node确实没有针对这种网络模式进行优化。请参阅此处的进一步说明(项目13):http://goldbergyoni.com/checklist-best-practice-of-node-js-in-production/

从…起npm@5.2.0,npm开始在通常的npm旁边安装一个新的二进制文件npx。现在,使用一行代码从当前目录创建静态http服务器:

npx serve

or

npx http-server

一个好的“现成工具”选项可以是http服务器:

npm install http-server -g

要使用它:

cd D:\Folder
http-server

或者,像这样:

http-server D:\Folder

过来看:https://github.com/nodeapps/http-server

对于开发工作,您可以使用(express 4)https://github.com/appsmatics/simple-httpserver.git

你可以试着为我服务

使用它非常简单:

ServeMe = require('serve-me')();
ServeMe.start(3000);

仅此而已。

PD:默认情况下提供的文件夹为“public”。