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

A horrible introduction to using modern JavaScript tooling with D3

Chapter 4

Meeting npm

Now that we have node installed, we’re going to learn about its most important part: its package manager! Packages are pieces of code and tools that were written by someone else.

For example, instead of writing a ton of code that talks to a web server to download web pages, there’s a package that will do it for me. Or instead of writing a ton of code that turns 3 into      3, we can use a package to do that too! (I’m not kidding)

Note: Packages and libraries and modules are the same thing. People refer to packages as modules when using JavaScript.

The package manager for JavaScript is called npm, node package manager. If you know Python, it’s just like pip.

Let’s try to upgrade npm, just in case we don’t have the most recent version. We’re going to use npm to upgrade itself!

If you want to see what packages you already have installed, you can use npm list. Give it a shot!

Maybe you don’t have anything installed? No big deal, we’ll install a package in our next step.

A big difference between npm and other package managers like pip is that npm installs things just for a specific project. When you’re working with Python, you have to try extra hard to say, “install this specific BeautifulSoup for this specific project,” but npm does it automatically.

This is kind of a pain if you keep using the same packages again and again and again, but it really helps keep your code organized, and ends up being worth it. Each project only has the exact modules that it needs, and if you need version 4.5 of something for one project and version 7.6 for another project it’s no big deal!

Another note: There are always a thousand options for everything in the node.js world. In this case, some people use yarn instead of npm. yarn was better than npm for like a year, but then npm absorbed all of its good parts and is now perfect and fine and has fewer bugs than yarn.