All I want to do is have some fun...

Tittle image

All developers want to just be able to "double click" an index.html page to test it.
Its never that easy... I'm sure a lot of people reading this have seen this error:

Cross Origin

I love SEO so let me type out what the image says:

XMLHttpRequest cannot load [--url--] . Recieved an invalid response. Origin 'null' is therefore not allowed access.

Sometimes you just want a simple sandbox, you dont want a server, you just want to write some html/js/css and test it. Well this blog is for you. I have two simple options for serving content.

Imagine a world where serve . results in:

Http Server running at http://localhost:8000/

Its as easy as:

  1. Install node.js.
  2. Download web-server.js
  3. Copy web-server.js to some path (I put mine in /user/local/bin)
  4. Update/Create ~/.bash_profile . Add: alias serve='node /usr/local/bin/web-server.js'
  5. Restart bash/terminal.
  6. Navigate to the directory you want to host and type serve ... volia!

Now since I love python, it comes installed on Mac.. a better less cool alternative is:

python -m SimpleHTTPServer ...

To take it one step further:

  1. Update/Create ~/.bash_profile . Add alias serve='python -m SimpleHTTPServer'
  2. Restart terminal/bash
  3. serve

Hopefully that last step felt a little familiar...
Same exact result, but I created mine first!

Nick Capito

Professional developer in all things generic. Good at AngularJS, CSS3 , Sass, .NET, Azure, Node. Love dogs. In an alternate live I would have been an American Cesar Millan.

Richmond, VA