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.
13 Answers13
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
5 Comments
npx http-server from the folder you want to share. To add CORS you can runnpx http-server --cors.cmd as an administrator-p <myPortNum> or--port <myPortNum>, for examplehttp-server -p 1337You 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
5 Comments
python3 -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.python -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)1 Comment
If you haveNode.js installed then from the folder you want to share you can simply run:
npx http-serverTo add CORS you can run:
npx http-server --cors1 Comment
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).
1 Comment
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
- In CMD, run the command to install http server-
If you have specific html file. Run following command in CMD.-
http-server fileNameby default port is
8080Go to your browser and type
localhost: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
Comments
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}
Comments
You can try installing one of the following localhost softwares:
- xampp
- wamp
- ammps server
- 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)
Comments
Another option if you have Node.js installed,
npx serve .It will serve you a static site/single page application in the current directory.
Comments
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
Comments
You can also use PHP to server the files in http
make sure you installed PHP, run the below command to verify
php --versionif PHP is not installed run below command to install it
sudo apt install php7.4-cliOnce after the installation go to the file path and execute the below command in the terminal
php -S localhost:8000Comments
justnpx serve it's more compatible with esmodule
Comments
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.
- Download VS Code from microsft
- Install "Live Server" extension in vs code
- Add folder and run HTML file.
I found this method fromhere in Youtube video.
Comments
Explore related questions
See similar questions with these tags.











