Easy way to start a web server

alexanderalemayhu

Alexander Alemayhu

Posted on March 18, 2020

Easy way to start a web server

You can always use a bundler in development mode but sometimes you just want a simple HTTP server with basic security and isolated ๐Ÿ˜‰ My favorite tool for that is python. On macOS and Ubuntu, it's installed by default so no setup is usually required.

This works well because Python ships with an HTTP module in the standard library so it's straightforward to start a server:

$ python -m http.server 2020
Serving HTTP on 0.0.0.0 port 2020 (http://0.0.0.0:2020/) ...
Enter fullscreen mode Exit fullscreen mode

Or if you are still using python2

$ python -m SimpleHTTPServer 8000
Serving HTTP on 0.0.0.0 port 8000 ...
Enter fullscreen mode Exit fullscreen mode

In most cases, the above is enough but in rare cases, you want to bind explicitly to an address:

python -m http.server 2020 --bind 192.168.0.6 

Serving HTTP on 192.168.0.6 port 2020 (http://192.168.0.6:2020/) ...
Enter fullscreen mode Exit fullscreen mode

Thanks for reading.

๐Ÿ’– ๐Ÿ’ช ๐Ÿ™… ๐Ÿšฉ
alexanderalemayhu
Alexander Alemayhu

Posted on March 18, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

ยฉ TheLazy.dev

About