Node.js快速文件服务器(通过HTTP的静态文件)

本文翻译自:Node.js quick file server (static files over HTTP)

Is there Node.js ready-to-use tool (installed with npm ), that would help me expose folder content as file server over HTTP. 是否有Node.js即用型工具(随npm安装),它将帮助我通过HTTP将文件夹内容作为文件服务器公开。

Example, if I have 例如,如果我有

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

Then starting in D:\\Folder\\ node node-file-server.js I could access file via 然后从D:\\Folder\\ node node-file-server.js我可以通过

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

Why is my node static file server dropping requests? 为什么我的节点静态文件服务器删除请求? reference some mystical 引用一些神秘的东西

standard node.js static file server 标准的node.js静态文件服务器

If there's no such tool, what framework should I use? 如果没有这样的工具,我应该使用什么框架?

Related: Basic static file server in NodeJS 相关: NodeJS中的基本静态文件服务器


#1楼

参考:https://stackoom.com/question/16XAE/Node-js快速文件服务器-通过HTTP的静态文件


#2楼

If you use the Express framework , this functionality comes ready to go. 如果使用Express框架 ,则可以使用此功能。

To setup a simple file serving app just do this: 要设置一个简单的文件服务应用,只需执行以下操作:

mkdir yourapp
cd yourapp
npm install express
node_modules/express/bin/express

#3楼

connect could be what you're looking for. 连接可能是您想要的。

Installed easily with: 易于安装:

npm install connect

Then the most basic static file server could be written as: 然后,最基本的静态文件服务器可以写成:

var connect = require('connect'),
    directory = '/path/to/Folder';

connect()
    .use(connect.static(directory))
    .listen(80);

console.log('Listening on port 80.');

#4楼

Searching in NPM registry https://npmjs.org/search?q=server , I have found static-server https://github.com/maelstrom/static-server 在NPM注册表https://npmjs.org/search?q=server中搜索,我找到了静态服务器https://github.com/maelstrom/static-server

Ever needed to send a colleague a file, but can't be bothered emailing the 100MB beast? 是否曾经需要向同事发送文件,但是是否可以通过电子邮件发送100MB的野兽? Wanted to run a simple example JavaScript application, but had problems with running it through the file:/// protocol? 是否想运行一个简单的示例JavaScript应用程序,但是在通过file:///协议运行它时遇到问题? Wanted to share your media directory at a LAN without setting up Samba, or FTP, or anything else requiring you to edit configuration files? 是否想在不设置Samba或FTP或其他任何需要编辑配置文件的情况下在LAN上共享媒体目录? Then this file server will make your life that little bit easier. 然后,此文件服务器将使您的生活变得更加轻松。

To install the simple static stuff server, use npm: 要安装简单的静态填充服务器,请使用npm:

 npm install -g static-server 

Then to serve a file or a directory, simply run 然后要提供文件或目录,只需运行

 $ serve path/to/stuff Serving path/to/stuff on port 8001 

That could even list folder content. 甚至可以列出文件夹内容。

Unfortunately, it couldn't serve files :) 不幸的是, 它无法提供文件 :)


#5楼

I use Houston at work and for personal projects, it works well for me. 我在工作和个人项目中使用休斯顿,对我来说效果很好。

https://github.com/alejandro/Houston https://github.com/alejandro/休斯顿


#6楼

I know it's not Node, but I've used Python's SimpleHTTPServer: 我知道它不是Node,但是我使用了Python的SimpleHTTPServer:

python -m SimpleHTTPServer [port]

It works well and comes with Python. 它运行良好,并带有Python。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值