· Coding · 1 min read

Tip: serve local files over HTTP with one console command

This weekend I was playing with Facebook’s JavaScript SDK and I needed a quick way to serve over HTTP the files I was working on, so that I could access them in a browser window at http://localhost.

I didn’t want to go through the hassle of setting up Apache on my Mac, though, and I was looking for some quick alternative to installing a local web server. After some Googling, I found a wonderful one liner that did the job, provided that you have Python installed.

Open a Terminal window and go to the directory containing the files you want to serve and run:

python -m SimpleHTTPServer

or, if you are using Python 3,

python -m http.server

you will then be able to access your files on http://localhost:8000/. (You can specify a different port number by passing the number as last argument, just remember that you need root permissions to open sockets on ports lower than 1024.)

Share:
Back to Blog

Related Posts

View All Posts »
· 2 min read

One of the things I was not expecting when I moved to Amsterdam was its active and vibrant tech community. Appsterdam, a non-profit organization focused around aggregating people with a passion for te...

User authentication with webapp2 on Google App Engine

User authentication with webapp2 on Google App Engine

· 13 min read · 141 comments

Google App Engine for Python ships with the capability to manage user accounts without the need of any additional library. This functionality is, however, insufficiently documented. This post is a step-by-step tutorial addressing user registration, login, password reset and a few other details.

· 6 min read · 2 comments

I spend most of my days at work on powerful IDEs like Eclipse or Netbeans, tools so advanced in functionalities that their feature lists span over several pages. Their power, however, has its own draw...

· 6 min read

Delivering feedback is a critical part of my day job as a manager at Google. However, it took me a while to realize that receiving feedback is one of the skills that helped me grow the most in my career. Here a few things I learned in the process.