125
Closed. This question needsdetails or clarity. It is not currently accepting answers.

Want to improve this question? As written, this question is lacking some of the information it needs to be answered. If the author adds details in comments, considerediting them into the question. Once there's sufficient detail to answer, vote to reopen the question.

Closedlast year.

The community reviewed whether to reopen this questionlast year and left it closed:

Original close reason(s) were not resolved

I have an HTML file and I run it on localhost. But, this file includes a mirror using a webcam. For example, how can I runthis HTML file on localhost? Webcam starts in this example when checking to live checkbox.

askedJul 21, 2016 at 7:10
Volkan Şahin's user avatar
0

13 Answers13

243

You can run your file inhttp-server.

1> HaveNode.js installed in your system.

2> In CMD, run the commandnpm install http-server -g

3> Navigate to the specific path of your file folder in CMD and run the commandhttp-server

4> Go to your browser and typelocalhost:8080. Your Application should run

answeredJan 21, 2018 at 6:53
Clinton Roy's user avatar
Sign up to request clarification or add additional context in comments.

5 Comments

Thank you very much. That is exactly what I was looking for! Easy to do and works ;)
Even faster for one-time run isnpx http-server from the folder you want to share. To add CORS you can runnpx http-server --cors.
Make sure to run thecmd as an administrator
@sax if you put that in an answer I would vote on it!
To change the port (maybe you're already running something on 8080), use-p <myPortNum> or--port <myPortNum>, for examplehttp-server -p 1337
129

You can usepython -m http.server. By default the local server will run on port 8000. If you would like to change this, simply add the port numberpython -m http.server 1234

If you are using python 2 (instead of 3), the equivalent command ispython -m SimpleHTTPServer

DBolton's user avatar
DBolton
5704 silver badges10 bronze badges
answeredJul 21, 2016 at 7:13
Nora's user avatar

5 Comments

I create HTTPServer. What will i do now?
OK. I am done. I transport my project to C:/Python27 and i run it on127.0.0.1:8000
So you run the python command "python -m SimpleHTTPServer" and then navigate tolocalhost:8000 in your browser and click the desired html file. Great solution!
The python 3 equivalent ispython3 -m http.server You want to navigate to the directory that contains the files you wish to open locally, and then run that command. Then open up localhost:8000 if you are using the default port.
You should usepython -m http.server --bind 127.0.0.1 to ensure your server can only be reached fromthis device for testing. Otherwise everyone can reach your server viahttp://192.168.0.10:8000 (change to your IP in local network)
22

If you are running Python3, you may want to instead try:

python -m http.server

Seethis answer.

answeredAug 13, 2018 at 1:16
MrE's user avatar

1 Comment

You should use python -m http.server --bind 127.0.0.1 to ensure your server can only be reached from this device for testing. Otherwise everyone can reach your server via192.168.0.10:8000 (change to your IP in local network)
20

If you haveNode.js installed then from the folder you want to share you can simply run:

npx http-server

To add CORS you can run:

npx http-server --cors
answeredNov 20, 2021 at 7:50
sax's user avatar

1 Comment

Thanks a lot. Its working on end is "npx http-server"
14

On macOS:

Open Terminal (or iTerm) installHomebrew then runbrew install live-server and run live-server.

You also can installPython 3 and runpython3 -m http.server PORT.

On Windows:

If you have VS Code installed open it and install extension liveserver, then click Go Live in the bottom right corner.

Alternatively you can install WSL2 and follow the macOS steps via apt (sudo apt-get).

On Linux:

Open your favorite terminal emulator and follow the macOS steps via apt (sudo apt-get).

answeredSep 2, 2020 at 15:21
SamuelFischerCode's user avatar

1 Comment

Your VSCode suggestion was perfect for me. I was already using VSCode and I just needed a way to host a demo site locally for me to play around. The Go Live extension is a perfect one-click solution
9
  • Install Node js -https://nodejs.org/en/

  • go to folder where you have html file:

    • In CMD, run the command to install http server-npm install http-server -g
    • To load file in the browser run -http-server
  • If you have specific html file. Run following command in CMD.-http-server fileName

  • by default port is8080

  • Go to your browser and typelocalhost:8080. Your Application shouldrun there.

  • If you want to run on different port:http-server fileName -p 9000

Note : To run your .js file run:node fileName.js

answeredFeb 14, 2019 at 12:48
Ritu Gupta's user avatar

Comments

5

As Nora suggests, you can use the python simple server.Navigate to the folder from which you want to serve your html page, then executepython -m SimpleHTTPServer.Now you can use your web-browser and navigate tohttp://localhost:8000/ where your page is being served.If your page is named index.html then the server automatically loads that for you. If you want to access any other page, you'll need to browse tohttp://localhost:8000/{your page name}

answeredJul 21, 2016 at 8:18
Anuj Gautam's user avatar

Comments

3

You can try installing one of the following localhost softwares:

  1. xampp
  2. wamp
  3. ammps server
  4. laragon

There are many more such softwares but the best among them are the ones mentioned above. they also allow domain names (for example:example.com)

answeredApr 4, 2020 at 6:50

Comments

2

Another option if you have Node.js installed,

npx serve .

It will serve you a static site/single page application in the current directory.

Reference

answeredJun 27, 2023 at 14:19
Philip's user avatar

Comments

1

You can install Xampp and run apache serve and place your file to www folder and access your file at localhost/{file name}or simply at localhost if your file is named index.html

answeredAug 21, 2019 at 10:40
HamzaMushtaq's user avatar

Comments

1

You can also use PHP to server the files in http

make sure you installed PHP, run the below command to verify

php --version

if PHP is not installed run below command to install it

sudo apt install php7.4-cli

Once after the installation go to the file path and execute the below command in the terminal

php -S localhost:8000
answeredJan 25, 2022 at 0:32
Surya Venkatapathi's user avatar

Comments

1

justnpx serve it's more compatible with esmodule

answeredDec 29, 2022 at 2:25
sema toghem's user avatar

Comments

0

I have explored many methods as I wanted to host virtual tour on local host as it wasn't working as browser was opening it as a file. I think following is by far the easiest method.

  1. Download VS Code from microsft
  2. Install "Live Server" extension in vs code
  3. Add folder and run HTML file.

enter image description here

I found this method fromhere in Youtube video.

answeredApr 12, 2024 at 14:23
Aamir Shahzad's user avatar

Comments

Protected question. To answer this question, you need to have at least 10 reputation on this site (not counting theassociation bonus). The reputation requirement helps protect this question from spam and non-answer activity.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.