Skip to content
Matthias Bussonnier edited this page Jan 26, 2017 · 8 revisions

Terminal

To run http.server, you are first going to want to become familiar using the Mac OS X terminal. The terminal provides "shell" access to your computer. You can browse directories and execute applications via text-based commands. You can find the Terminal app in Applications->Utilities->Terminal. Run it and you'll see something like.

Terminal

The blinking cursor is the "prompt", where you can execute a command. Here is a list of some common commands you'll need.

  • cd - change directory. The following, for example, will set the current path to your desktop. You'll want to replace "shiffman" with your username. cd /Users/shiffman/Desktop.
  • pwd - print working directory. This will print out the current directory.
  • ls - list the contents of the current directory.

This is barely scratching the surface of what you can do with unix commands. Allison Parrish's class also has a tutorial about using unix commands to manipulate text data. But we'll stop here, after all, we're just here to run a simple web server.

Running http.server

Your job is to get terminal to point to the directory on your computer where you are storing your p5.js work. On my computer I've got a ton of examples in a directory called "The-Nature-of-Code-Examples-p5.js". So I'm going to browse to it by doing the following.

$ cd /Users/shiffman/Documents/noc/The-Nature-of-Code-Examples-p5

(You don't need to type the '$' I'm just using it to represent a prompt.)

Once I'm there, I can start up a web server with the following command.

$ python -m http.server

I should then see:

Serving HTTP on 0.0.0.0 port 8000 ...

This means the server is up and running at localhost on port 8000. And this means I can type http://localhost:8000/ into the address of a web browser and I'll see:

localhost

A couple more terminal tips

  • If you don't feel like typing a long path to a directory on your computer, you can get to it quickly by dragging a folder from the finder into terminal. It'll magically transform into the path!
  • You can also "auto-complete" directories and filenames using TAB.
  • You can repeat previous commands by using the up and down arrow keys.

Some extra steps if you are on windows

Before you can run a local server on windows with python, you'll need follow a few steps.

  1. Download and install python.

  2. You'll need a console application that lets you interact with Git and your computer in much the same way as the Terminal application on Apple computers. There are several options.

  3. Install Git Bash

  • Download and install git.

  • use all the default settings.

  • When you get to the Adjusting your PATH environment screen, be sure to choose the option for Use Git Bash Only.

  • You should have now have a program in your Start Menu called Git Bash. If you hit the Windows key to pull up the start menu and type “git bash” you should see the program highlighted.

  • You will now need to make sure that Git Bash recognizes python. You can do this temporarily with this command in Git Bash: PATH=$PATH:/c/Python36/ (or whatever version of python you are running). However if you want this to be permanent you'll need to add c:\python36 to your system environment variable path. Here is how you access that..

  • An alternative to Git Bash is the windows built-in command prompt. This should work but you'll have to use DOS versions of the unix commands I'm showing in class.

  • An alternative to all of this is WAMPServer.

    • Download WampServer from http://www.wampserver.com/en/.
    • Install WampServer and follow instructions.
    • The “www” directory will be automatically created (usually c:\wamp\www).
    • Create a subdirectory in “www” and put your HTML/JS files inside.
    • Open your internet browser and go to the URL : http://localhost/yourfile.html.