Category Archives: Web

Simple Web Server with Ruby or Python

I was developing a Javascript app and wanted to run a web server pointing to current directory.

Using Ruby

A simple script to start a WEBrick server. You can modify the root directory to a subfolder if you’d like. I named this script “server” with chmod +x so I can run it with ./server

#!/usr/bin/env ruby

require 'webrick'

server = WEBrick::HTTPServer.new(Port: 8000, DocumentRoot: ".")
Signal.trap('INT') { server.shutdown }
server.start

Python

A simple command using python -m SimpleHTTPServer