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
Here's another simple web server.
https://www.npmjs.com/package/hostr
Install
Change working director
And start
I use Houston at work and for personal projects, it works well for me.
https://github.com/alejandro/Houston
You can try serve-me
Using it is so easy:
Thats all.
PD: The folder served by default is "public".
For the benefit of searchers, I liked Jakub g's answer, but wanted a little error handling. Obviously it's best to handle errors properly, but this should help prevent a site stopping if an error occurs. Code below:
There is another static web server that is quite nice: browser-sync.
It can be downloaded using node package manager:
After installation, navigate to the project folder in the cmd prompt and just run the following:
It will start catering all the files in the current folder in the browser.
More can be found out from BrowserSync
Thanks.
First install node-static server via
npm install node-static -g
-g is to install it global on your system, then navigate to the directory where your files are located, start the server withstatic
it listens on port 8080, naviaget to the browser and type localhost:8080/yourhtmlfilename.