DEV Community

Thomas Rigby
Thomas Rigby

Posted on • Originally published at thomasrigby.com on

Quick and dirty server 2

A python

I wrote last year about spinning up a quick and dirty server using Python.

Since then, I have moved to using Python 3 (woop woop!) and, the first time I ran my funky little srv 1337 function I got an error! 😱

"No module named SimpleHTTPServer"

According to the Python 2.7 documentation

The SimpleHTTPServer module has been merged into http.server in Python 3.

So, the simple-enough solution is to replace SimpleHTTPServer with http.server.

  1. Navigate to the folder you want to serve
  2. python -m http.server
  3. Open http://localhost:8000

What if PORT 8000 is in use?

Pass a different port number like this: python -m http.server %%PORT_NUMBER%%

If you want it to be even simpler - stick this somewhere in your bash config!

srv() {
  python -m http.server $1
}

Enter fullscreen mode Exit fullscreen mode

As before, it doesn't come with any of the fancy stuff that other "local server" plugins might come with like hot reloading or compiling Scss but, if all you want is a small static site launching, why reach for another dependency?

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay