O'Reilly logo

D3 for the Impatient by Philipp K. Janert

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Appendix A. Setup, Tools, Resources

Setup

To work with D3, you need to run a web server, either locally or hosted, to serve pages, JavaScript files, and other resources (such as data files). In principle, it is possible to load a local page using the file: protocol and any JavaScript files referenced by it. But browsers may prevent your JavaScript code from loading other resources, such as data files, in this way, depending on the browser’s cross-origin resource sharing (CORS) policy. Browsers are inconsistent in this regard; it is probably best to sidestep the issue by always using a web server when working with D3.

Setting up a web server need not be a challenge: several minimal web servers can be run without further configuration from the command line,1 and many programming languages include ready-to-use web server modules as well. The D3 website recommends http-server, which is a Node.js package. If you have the Node runtime and the npm package manager installed, you can install and run a web server using:2

npm install -g http-server
http-server ./project -p 8080

Because they are part of its standard distribution, Python’s web server modules are ubiquitous, but can be quite slow, even for development work (the -d argument requires Python 3.7 or later):

python -m http.server -d ./project 8080	 # Python 3
python -m SimpleHTTPServer 8080          # Python 2: current dir

The busybox set of tools should be installed on all Debian-derived Linux distributions by default. Its built-in web ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required