DIY & Music & Guitar & Beer & Tech

Very simple web-server

I’m playing with some JavaScript frameworks and some new editors. Brackets (adobe) is open source one, built particularly for developing web stuff. It has built-in server for live preview and it works really good. This, assuming that some simple mostly fast static content preview is desired. As soon as you save your file it updated the DOM. Latest version even runs JS changes on save – awesome!

But I also like Sublime text. I have configured it to my please with fast editing commands and I would like to be able to do work in it as well. Simplest possible solution? Well, Apache HTTPD is always nice to have installed on your computer but it feels like using canon to kill flies. While there are many lightweight web-servers out there (e.g. mongoose) there is something a bit more convenient. Python to rescue!

Simply use built-in web server in python is something that gives almost live feeling that brackets provides. In python2 you would do something like:

python -m SimpleHTTPServer 8000

And in python3:

python -m http.server 8000

Change port if you like and regardless, all your content will be available from the folder you started your server (in these examples at “localhost:8000/” ). I wouldn’t expect this embedded server to do all kinds of magic HTTPD can but for quick js/html/css editing – more than appropriate!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.