npm, Packages and Build Tooling
Manage dependencies with npm or pnpm, understand package.json and lockfiles, and use Vite, ESLint and Prettier.
Beginner · about 4 hours · difficulty 2/5
Learn first: JavaScript Fundamentals, Terminal and Command Line
Modern JavaScript is assembled from packages. Understanding the tooling turns mysterious install and build errors into routine fixes.
package.json
- dependencies ship with your app; devDependencies are for building and testing.
- scripts like dev, build, test and lint are the commands your team and CI run.
- Semantic versioning: ^1.4.2 allows minor and patch upgrades. Know what that means before you upgrade.
Lockfiles
package-lock.json or pnpm-lock.yaml pin exact versions so everyone installs the same tree. Commit it. Use npm ci in CI for clean, reproducible installs.
Package managers
npm comes with Node.js. pnpm is faster and stricter about undeclared dependencies and is popular in monorepos. Pick one per project and stick to it.
Build and quality tools
- Vite: fast dev server and bundler for React apps.
- ESLint: catches bugs and enforces conventions.
- Prettier: formats code so reviews focus on logic.
Pitfalls
- Installing a package for something a few lines of code can do. Every dependency is a security and maintenance cost.
- Deleting the lockfile to "fix" errors.
- Mixing npm and pnpm in one repo.
You are ready to move on when you can start a Vite project, add ESLint and Prettier, write custom scripts, and explain the difference between npm install and npm ci.
Key concepts
- package.json and scripts
- Dependencies vs devDependencies
- Semantic versioning
- Lockfiles and npm ci
- pnpm
- Vite
- ESLint and Prettier
- npm audit
Mini project
Scaffold a Vite project, add ESLint and Prettier with a pre-commit check, write scripts for dev, build, lint and format, and document them in the README.
Check yourself
Why should CI run npm ci instead of npm install, and why must the lockfile be committed?
Free resources
- npm Docs (npm)
- Vite Guide (Vite)
- ESLint: Getting Started (ESLint)