If you have node
and npm
installed, it’s as simple as this:
Make a directory that contains an index.html file
npx http-server
Visit
http://127.0.0.1:8080
1. Make a directory and create an index.html file
Let’s create a directory called my_website
. In it, we’ll create an index.html
file that looks like this:
<html lang="en"> <body> <h1>Dead simple http-server with node.js!</h1> </body> </html>
2. Start the web server
Open a terminal in the directory that contains index.html
, and type this:
npx http-server
You'll see something like this...
Starting up http-server, serving ./
Available on:
http://127.0.0.1:8081
http://10.0.1.6:8081
Notes
The port number that gets assigned to the server may differ for you – it depends on what you have running on your workstation
If you don’t have http-server, install it globally with
npm install -g http-server
3. Open a browser at the specified URL
You’ll see your index.html page rendered in the context of a running web server.
To kill the server, just quit the node process by hitting CTRL + C.