Step-by-step bootstrap
The next section covers detailed instructions to set up your development environment to rapidly create visualizations in later chapters. By the end of the chapter, you will have a working environment for the rest of the book (an example of a map running and an initial look at tools used to create visualizations).
A lightweight web server
Technically, most of the content we will craft can render directly in the browser without the use of a web server. However, we highly recommend you not to go ahead with this approach. Running a web server in your local development environment is extremely easy and provides several benefits:
- Geographic information, statistical data, and visualization code can be clearly separated into isolated files
- API calls can be stubbed and simulated, allowing easy integration into a full-stack application in the future
- It will prevent common mistakes when making AJAX calls to fetch geographic and statistical data (for example, the same-origin policy)
For our choice of the web server and other tools in our toolbox, we will rely on a Node.js package named http-server
. Node.js is a platform built on Chrome's JavaScript runtime, which is used to build fast, scalable network applications. The platform includes Node Package Manager (npm), which was created by other members of the vibrant Node.js community and allows the developer to quickly install packages of prebuilt software.
To install Node.js, simply perform the following steps:
- Go to the website http://nodejs.org.
- Click on the INSTALL button.
- Open the downloaded package and follow the defaults.
To test the installation, type in the following in the command line:
node –v v0.10.26 # or something similar should return
Now that Node.js and npm are installed, we can proceed to install the web server. When the web server is installed globally with the –g
command, it becomes easily accessible throughout the system.
Once on the command line, enter the following:
npm install -g http-server
You can quickly verify the package was installed by typing the following:
http-server
Then open your web browser to http://localhost:8080
. The browser should display a list of all the files in the directory from where you initiated the command.