Post

Run Local HTTP Server

If you want to do a quick development test with some HTML and some JavaScript a good solution is to fire up a HTTP server for local development testing. You can run/install this in the folder your working on

Run HTTP server without installing it:

1
npx http-server

Install HTTP server

1
npm install http-server

Or using homebrew on a mac

1
brew install http-server

Good for serving up simple html pages

Run / Start HTTP Server

First create your folder where you want to run your HTTP server. In this folder will contain all your HTML and JS files.

  • Add your HTML
1
2
3
4
5
6
7
8
9
10
11
12
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="myscript.js"></script>
  </head>
  <body>
    <h1>my title</h1>
  </body>
</html>
  • Add your JS
1
2
3
document.addEventListener("DOMContentLoaded", function (event) {
  console.log("dom loaded");
});
  • Run your server and start testing code.
1
http-server

Dependencies

Node js

This post is licensed under CC BY 4.0 by the author.