I wonder to know how can I make my .html project run not from file:// but as a localhost because one of the functions I've implemented requires getUserMedia which browsers instantly block, when loading from file://. I've done a lot of research on this but I'm still not understanding how it should be done, so if you can, please explain it in detail if it's not too pretentious of me, of course.
- You need some sort of http server - without knowing what OS you're running I wont recommend anything in particularJaromanda X– Jaromanda X2015-09-01 13:07:48 +00:00CommentedSep 1, 2015 at 13:07
- Install some IDE like NetBeans. Create Web project. add your html code to index html if its a single page application. Or the other way install server and run your project on that serverAnita– Anita2015-09-01 13:07:57 +00:00CommentedSep 1, 2015 at 13:07
- The most popular Webservers would benginx andApacheTom Doodler– Tom Doodler2015-09-01 13:09:17 +00:00CommentedSep 1, 2015 at 13:09
- @Jaromanda X, that's the goal to make it http://... and yeah, I'd prefer the second option - to create a.server and to make the folder with the project somehow hostable to my computer and it to run through this server... I've really a zero knowledge in server establishing,so far just javascript,.jquery, html and css, so don't wonder about my unawared comments, maybe... One guy told me that python can create localhost:/ but after I installed it it didn't work... Tx for the replays, so.far.KDX2– KDX22015-09-01 13:14:58 +00:00CommentedSep 1, 2015 at 13:14
- as I said, without knowing which OS you are running, it'd be presumptuous of me to recommend anything in particularJaromanda X– Jaromanda X2015-09-01 13:16:51 +00:00CommentedSep 1, 2015 at 13:16
5 Answers5
install node js
npm install -g http-serverfrom the directory containing html files.
http-server ./ -p 802 Comments
nodejs command prompt that was installed with nodejs. Then run thenpm command which will install other node packages on you system. then you can run thehttp-server from the same command prompt.I uselive-server on my mac by running the below code on the command line from inside the folder containing your index.html:
live-server --port=8000In addition to running index.html from localhost, live-server automatically reloads the page after any changes made to files that affect the dome for that page (i.e. .js or .css etc..) which can accelerate development.
Installation
You should probably install this globally.
npm install -g live-servernote:
- You neednode.js in order to use npm.
- --port= can be any free port and not nessessarly 8000.
Comments
If you are on Ubuntu (or any other similar Linux distro) run
apt-get install apache2then move your files to the /var/www/html folder, and navigate to localhost in your browser.
On Windows, you can installXAMPP, then move your files to wherever you installed it to in the\htdocs folder
Hope this helps, thanks.
2 Comments
python -m SimpleHTTPServer 8000
And you are good to go!
Start a server within seconds!
Note you do require an installed python
Comments
If you're using Python 3, then run this in the terminal:
python -m http.serverThis should start a local host at port 8000. This can be configured within a python script that starts the server and then configures to the wanted settings.
Find more at theHTTP servers Python 3.9 documents.
Edit
This will start a local server for you where you can run .JS, .HTML, and .CSS
Comments
Explore related questions
See similar questions with these tags.

