How to Open an HTML on Localhost

Below is the structured text using Markdown syntax:

Your file can be executed in an HTTP server.

  1. Install NODE.JS on your computer.
  2. Enter the command NPM in CMD. Set up the HTTP-SERVER -G.
  3. Open CMD, navigate to the precise location of your file folder, and execute the command. Web server
  4. Enter LOCALHOST:8080 into your browser. Your program ought to launch.
  • Python -m http.server is an option. The port on which the local server runs by default is 8000. To modify this, merely append the port number python -m http.server 1234.
  • Python -m SimpleHTTPServer is the equivalent command if you’re using Python 2 instead of Python 3.
  • If you’re using Python 3, you might want to try these instead: -m http.server in Python

If Node.js is installed on your system, you can run the following code from the folder you wish to share: http-server npx
You can run npx http-server --cors to add CORS.

Go to https://nodejs.org/en/ to install Node js.
Enter localhost:8080 into your browser. That’s where your application should run.

To operate on a different port: FileName: http-server -p 9000

On a Mac, launch iTerm or Terminal, install Homebrew, and then execute brew. Launch and install the live server.
Installing Python 3 and running python3 -m http.server PORT are other options.

On Windows, open Visual Studio Code, install the liveserver extension, and then select Go Live in the lower right corner.
As an alternative, you can use apt (sudo apt-get) to install WSL2 and follow the instructions for macOS.
On Linux, launch your preferred terminal emulator and use apt (sudo apt-get) to follow the macOS instructions.

You can use the Python Simple Server, just like Nora says. To serve your HTML page, navigate to the folder you want to use, then run python -m SimpleHTTPServer. You can now go to http://localhost:8000/ with a web browser. the location of the page’s service. The server will load your page automatically if it is named index.html. The URL to visit in order to view any other page is [http://localhost:8000/{your page name}](http://localhost:8000/{your page name}).

You may attempt to set up any of the following localhost applications: wamp, laragon, xampp, and ammps server

If Node.js is installed, you also have the option to use npx serve. In the current directory, it will provide you with a static site or single page application.

Installing Xampp and running Apache serve will allow you to put your file in the www folder and access it at localhost/{file name}, or just localhost if it’s an index.html file.

PHP can also be used to serve files over HTTP. Make sure PHP is installed by running the command below to confirm: --version php. Use the command below to install PHP if it isn’t already installed: Install php7.4-cli with sudo apt. Following installation, navigate to the file path and type the following command into the terminal: PHP- –S 8000 localhost

Merely npx serve It works better with esmodule.

Let’s investigate how to use a serverless HTML file.

  1. To open the file in your default browser, save it and then double click on it.
  2. The text "Hello World!" ought to appear on the page in the browser.