Run a file:// from http://localhost/
Asked Answered
D

5

6

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.

Darrelldarrelle answered 1/9, 2015 at 13:5 Comment(6)
You need some sort of http server - without knowing what OS you're running I wont recommend anything in particularZ
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 serverBedwarmer
The most popular Webservers would be nginx and ApacheStereo
@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.Darrelldarrelle
as I said, without knowing which OS you are running, it'd be presumptuous of me to recommend anything in particularZ
@Jaromanda X, I'm running Window 8.1Darrelldarrelle
P
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 install XAMPP, then move your files to wherever you installed it to in the \htdocs folder

Hope this helps, thanks.

Planish answered 1/9, 2015 at 16:48 Comment(2)
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! :)Darrelldarrelle
If you want it to run under Node, you will need to install the Node-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 WindowsPlanish
I
11

install node js

npm install -g http-server

from the directory containing html files.

http-server ./ -p 80

reference https://github.com/indexzero/http-server

Indwell answered 1/9, 2015 at 16:45 Comment(2)
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.Darrelldarrelle
@Darrelldarrelle you need to open a terminal or open the nodejs command prompt that was installed with nodejs. Then run the npm command which will install other node packages on you system. then you can run the http-server from the same command prompt.Indwell
P
3

I use live-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 need node.js in order to use npm.
  • --port= can be any free port and not nessessarly 8000.
Perusse answered 24/6, 2018 at 11:26 Comment(0)
P
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 install XAMPP, then move your files to wherever you installed it to in the \htdocs folder

Hope this helps, thanks.

Planish answered 1/9, 2015 at 16:48 Comment(2)
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! :)Darrelldarrelle
If you want it to run under Node, you will need to install the Node-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 WindowsPlanish
P
1

python -m SimpleHTTPServer 8000

And you are good to go!

Start a server within seconds!

Note you do require an installed python

Pearlinepearlman answered 25/6, 2018 at 16:13 Comment(0)
R
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 the HTTP servers Python 3.9 documents.

Edit

This will start a local server for you where you can run .JS, .HTML, and .CSS

Rapport answered 6/7, 2021 at 15:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.