Posted in:

If you’re ever working locally on a static website with a mix of HTML, CSS and JavaScript, you’ve probably run into the situation where simply testing the files in your web browser with a file:// link doesn’t work. Things like retrieving JSON or accessing the webcam require you to load the page via http://localhost instead.

So is there an easy way to start a webserver from any local folder? Well, if you have nodejs installed, then there is a super simple npm package called http-server which is ideal for this.

Just install it with npm install -g http-server, and then run it from whatever folder your website is in with http-server or even simpler hs.

Now browse to http://localhost:8080, and view your site.

Of course if you’re a seasoned web developer I’m sure you know about this already, as well as a thousand other ways to do the same thing. For a more advanced local server, there is browser-sync, which has the ability to live re-load the browser as you edit your local assets. But most of the time, http-server works just fine for me.