D3 + JavaScript Tooling's Not (Just) For Unicorns

A horrible introduction to using modern JavaScript tooling with D3

Chapter 3

Hello node

For millions and millions of years, you could only run JavaScript in a web browser, while Python and C++ and all of that lived on the command line.

But then one day everything changed.

In 2009, node.js appeared! It let you run JavaScript on the command line, which was absolute heresy. It was insane. It didn’t make any sense. Why would you run this garbage heap of a language in a place as serious as the command line?

That might have been a mystery, but people loved it. People flocked to it. It grew and it grew and it grew, and this newfound interest in JavaScript convinced JavaScript to get better and cooler and more useful.

You can see this by taking a peek at the schedule of JavaScript version releases:

Year JavaScript Version
1997 Version 1.0
1998 Version 2.0
1999 Version 3.0
??? THE DARK AGES. Version 4 was never released!
2009 Version 5.0
2011 Version 5.1
2015 Version 6.0
2016 Version 7.0
2017 Version 8.0
2018 Version 9.0

We had zero new versions of JS come out for ten years, and now we have a new version come out every single year. And it’s all thanks to node!

Installing node.js

To install node:

  • Mac users need to install Homebrew if it isn’t installed yet, and then type brew install node.
  • Windows users can use the installer from nodejs.org. Restart once it’s done.

Extra setup for OS X

If you’re on a more recent version of OS X, there’s some extra security that prevents you from saving files to certain parts of the computer. Unfortunately, this is where node usually saves things you install!

To fix this, we’re going to tell node to save into a different directory. After you’ve installed node, run the following code to make the change.

It won’t give you any output, but it should work fine!

Note: If you’ve previously installed node packages globally with npm install -g, you’ll need to reinstall those packages before you use them again.