CPNT 262 Day 13 - Introduction npm and dependencies
Housekeeping
- Daily submission counts
Trophy of the day
- Example app using an
npm
package
1. Spoiler Demos
2. npm
Package Manager
Materials
- Takeaways: Introduction to
npm
- Prep:
- Anatomy of a
package.json
File on Digital Ocean - The
package.json
guide - Video: NPM Crash Course by Traversy Media
- NodeJS: An introduction to the npm package manager
- Anatomy of a
Activity: File size - before and after
- Download or clone the
hello-npm
project to your workspace. - Navigate to the root of the project on the command line.
- Use your operating system to determine the file size of this new project and how many files there are:
- File size: 188 kB on disk
- Number of items: 5 files
- Install dependencies with
npm install
- Check the file size and number again:
- File size: ???
- Number of files: ???
- Questions to ask:
- What has changed?
- What is taking up the extra disk space?
- Would we want to include
node_modules
in our repositories? Hint: the answer is no.
3. Ignoring node_modules
Materials
We want to exclude the node_modules
directory (with a .gitignore
file) for a few reasons:
- Including the directory will bloat the file size of your repos, which we'll see later.
- Even if the file size of
node-modules
is small, it will "pollute" your commit history with changes you didn't make because the directory is auto-generated and auto-updated. - There's no reason not to!
npm
can rebuild thenode_modules
directory at anytime with thenpm install
command. You only need to commitpackage.json
.
Key Takeaways
- Use your global
.gitignore
for files that your operating system might add to your projects. - Use your project
.gitignore
for project-specific files that your team members all need to exclude.
4. Initializing npm
projects and installing packages
Materials
Activity: Starter packages
- Install one or all of these packages:
- For any given package, create an example app by following the usage instructions.
- Have one of your classmates clone and run your demo app without including
node_modules
.
Lab Time
- Assignment 4
- Example
npm
package demo - Sharing your package demo
Prep
NPM Basics
- Video: NPM Crash Course by Traversy Media
- An introduction to the npm package manager
- Where does npm install the packages?
- Semantic Versioning using npm
package.json
- Anatomy of a
package.json
File on Digital Ocean - The
package.json
guide