1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > Node.js快速文件服务器(通过HTTP的静态文件)

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

时间:2021-12-26 07:48:38

相关推荐

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

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

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

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

D:\Folder\file.zipD:\Folder\file2.htmlD:\Folder\folder\file-in-folder.jpg

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

http://hostname/file.ziphttp://hostname/file2.htmlhttp://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楼

参考:/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 yourappcd yourappnpm install expressnode_modules/express/bin/express

#3楼

connectcould 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 /search?q=server , I have found static-server /maelstrom/static-server在NPM注册表/search?q=server中搜索,我找到了静态服务器/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.我在工作和个人项目中使用休斯顿,对我来说效果很好。

/alejandro/Houston/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。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。