Up until now, we've been writing our own JavaScript to do fancy things on our webpages. What nomads we are!

But as you know, website do a lot more than, say, fetching some jokes from a dad joke generator. They have to start video calls, refresh Twitter timelines with the latest woke content, host message boards with real time updates, etc etc etc.

So, the handle all of these ever fancier functionalities, we need to stand on the backs of giants that have already written that code for us.

That's where package management comes in.

What is package management?

<aside> 💡 Before package management existed in JavaScript, you just downloaded external libraries directly from the web as .js files. This works just fine today, but it has a couple problems: you can't update these dependencies very easily (you have to go back to the website to download again), and the order that you import them into your project might break things. Package management solves both of these issues.

</aside>

What is NPM?

NPM → Node Package Registry

In other words, this is the package manager of choice for JavaScript. This is true both for frontend and backend JavaScript!

It is a terminal based tool as well, so you'll need to open that scary command line in order to install your packages. Don't worry, the syntax is pretty easy to get the hang of!

Using NPM

Installing

First, you'll need to download Node. This lets you run both NPM (for frontend and backend) and Node commands (for backend)

Install the LTS version:

Node.js

Setup

Say you have a new project directory ready to go. To get package management set up, you'll need to generate a package.json file to keep track of all the packages you will install. We'll explain what this does in a bit!