5

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.

askedSep 1, 2015 at 13:05
KDX2's user avatar
6
  • You need some sort of http server - without knowing what OS you're running I wont recommend anything in particularCommentedSep 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 serverCommentedSep 1, 2015 at 13:07
  • The most popular Webservers would benginx andApacheCommentedSep 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.CommentedSep 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 particularCommentedSep 1, 2015 at 13:16

5 Answers5

11

install node js

npm install -g http-server

from the directory containing html files.

http-server ./ -p 80

referencehttps://github.com/indexzero/http-server

answeredSep 1, 2015 at 16:45
corn3lius's user avatar
Sign up to request clarification or add additional context in comments.

2 Comments

ok, I've installed node js and now what should I do with those two lines of code.instructions or whatever they are? I don't understand how to install this one ' npm install -g http-server ' into my directory containing the project and the second one ' http-server ./ -p 80 ' I've no idea where to write, also.
@KDX2 you need to open a terminal or open thenodejs 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.
3

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=8000

In 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-server

note:

  • You neednode.js in order to use npm.
  • --port= can be any free port and not nessessarly 8000.
answeredJun 24, 2018 at 11:26
Hassan AlMandil's user avatar

Comments

1

If you are on Ubuntu (or any other similar Linux distro) run

apt-get install apache2

then 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.

answeredSep 1, 2015 at 16:48
Wargog's user avatar

2 Comments

I tried the method you suggested and it worked!!! The all I did was to install XAMPP and after that to simply drag my files into htdocs. After that you've to simply go to browser and write localhost/your-project-name.html, (html in my case...). Now the mic is working which is SUPER news. Thanks a lot for the help. I wished to rather make it work with node js as it doesn't need to move the project to another folder but... who cares, it works and it's great! Thank you! :)
If you want it to run under Node, you will need to install theNode-Windows package, then use their web server for your project specifically. I'm not a Node expert, just starting to learn it myself actually. But to my understanding, that's all you need to run a Node project on Windows
1

python -m SimpleHTTPServer 8000

And you are good to go!

Start a server within seconds!

Note you do require an installed python

answeredJun 25, 2018 at 16:13
runningmark's user avatar

Comments

1

If you're using Python 3, then run this in the terminal:

python -m http.server

This 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

answeredJul 6, 2021 at 15:18
lua_python_java's user avatar

Comments

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.