Install a package
Add other people's code to your project
⏱ Est. ~9 min
01 · Read
You're about to install your first npm package: Express. Express is the most popular web server framework for JavaScript. Over 30 million engineers download it every week.
When you run npm install, three things happen:
1. npm downloads the package from the registry 2. It stores the code in a folder called node_modules 3. It records the package name in your package.json under dependencies
Before you continue, make sure you're still in the my-server folder.
02 · Real-machine exercise
Install Express. This will download Express and all the packages it depends on into your project. Run the command below in your terminal, wait for it to finish, then click "I did it" to continue.
npm install express
03 · Real-machine exercise
Now look at package.json again. You should see a new dependencies section listing Express.
cat package.json
04 · Quiz
Which file tracks your project's dependencies so others can install them too?
- package.json
- node_modules/index.js
- dependencies.txt
- .npmrc
05 · Real-machine exercise
Let's peek at node_modules — the folder where npm stores all downloaded packages. Express needs many other packages to work, so you'll see more than just 'express' in there.
ls node_modules | head -20
06 · Fill in the blank
To install Express, type npm _____ express.
07 · Read
That's a lot of folders! Express depends on other packages, which depend on other packages. This is called the dependency tree.
Important: you never commit node_modules to git. It can be thousands of files, hundreds of megabytes. Your package.json records what you need, and anyone who clones your project can run npm install to download everything again.
That's why package.json is so important — it's the recipe. node_modules is the ingredients.
💡 Picture thispackage.json is the shopping list. node_modules is the actual groceries. You share the list, not a truckload of food.
Key points
- npm install downloads packages into node_modules/
- package.json records which packages your project depends on
- Never commit node_modules to git — it's too big
- Anyone can run npm install to rebuild node_modules
08 · Quiz
A teammate clones your GitHub project. There's no node_modules folder. What do they run to get all the dependencies?
- They have to manually download every package from npmjs.com
- npm install — it reads package.json and downloads everything
- node install — Node.js handles dependency management
- They can't — without the original node_modules the project won't work
Other lessons in this chapter
⚠ The full interactive experience needs JavaScript. Please enable it and reload.
※ This is an independent Traditional Chinese teaching project — not an official Anthropic product. Claude™ is a trademark of Anthropic, PBC.