Skip to Content
D3 for the Impatient
book

D3 for the Impatient

by Philipp K. Janert
May 2019
Intermediate to advanced
256 pages
6h 5m
English
O'Reilly Media, Inc.
Book available
Content preview from D3 for the Impatient

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

D3.js in Action, Second Edition

D3.js in Action, Second Edition

Elijah Meeks
D3.js in Action

D3.js in Action

Elijah Meeks

Publisher Resources

ISBN: 9781492046783Errata Page