DEV Community

loading...
Cover image for Quick and dirty server

Quick and dirty server

thomasxbanks profile image Thomas Banks Originally published at thomasxbanks.com on ・1 min read

I often find myself working on proof of concepts that consist of (at most) an index.html, style.css, and index.js.

It always seems overkill to have some kind of "local server" plugin imported into the project - especially because I use a MacBook Pro and it has Python installed by default.

A neat little trick for serving a static site without additional dependencies is this…

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

What if PORT 8000 is in use?

Pass a different port number like this: python -m SimpleHTTPServer %%PORT_NUMBER%%

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

srv() {
  python -m SimpleHTTPServer
}
Enter fullscreen mode Exit fullscreen mode

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?

Discussion (2)

pic
Editor guide
Collapse
sidchaudhary04 profile image
Siddharth Chaudhary

You can also do it like this

python3 -m http.server (port)

Collapse
mellen profile image
Matt Ellen

That's amazing!