Is there Node.js ready-to-use tool (installed with npm
), that would help me expose folder content as file server over 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
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
If there's no such tool, what framework should I use?
Related: Basic static file server in NodeJS
Take a look on that link.
You need only to install express module of
node js
.You can access your file like http://hostname/Folder/file.zip
One-line™ Proofs instead of promises
The first is
http-server
,hs
- linkThe second is
serve
by ZEIT.co - linkFollowing are available options, if this is what helps you decide.
If you need to watch for changes, see
hostr
, credit Henry Tseng's answerconnect could be what you're looking for.
Installed easily with:
Then the most basic static file server could be written as:
DEMO/PROTO SERVER ONLY
If that's all you need, try this:
note: You need to use "/index.html" as part of your address ie "http://localhost:3000/index.html"
If you are intrested in ultra-light http server without any prerequisites you should have a look at: mongoose
Here is my one-file/lightweight node.js static file web-server pet project with no-dependency that I believe is a quick and rich tool which its use is as easy as issuing this command on your Linux/Unix/macOS terminal (or termux on Android) when node.js (or
nodejs-legacy
on Debian/Ubuntu) is installed:(different commands exist for Windows users on the documentation)
It supports different things that I believe can be found useful,
curl pad.js.org | node - -h
[sudo] npm install -g pad.js
and then use its installed version to have access to its options:pad -h
[sudo] docker run --restart=always -v /files:/files --name pad.js -d -p 9090:9090 quay.io/ebraminio/pad.js
The features described above are mostly documented on the main page of the tool http://pad.js.org which by some nice trick I used is also the place the tool source itself is also served from!
The tool source is on GitHub which welcomes your feedback, feature requests and ⭐s!