learn.colinkim.dev

npm reference

Use this page as a compact reference for the npm commands you are most likely to need first.

This page is a quick reference, not a replacement for the earlier lessons.

Use it when you already know the basic concepts and want the right command quickly.

Install the dependencies a project already declares

Run this in a project directory that already has a package.json file:

npm install

This installs the dependencies already declared by the project.

Add a new dependency

npm install react

This adds react to dependencies, updates package-lock.json, and installs it into node_modules.

To add more than one dependency at once:

npm install react react-dom

Add development dependencies

npm install -D typescript

To add several development dependencies in one command:

npm install -D typescript eslint prettier

Use this for packages needed during development, testing, building, or formatting.

Remove a package

npm uninstall react

This removes the package from the project manifest, updates the lockfile, and removes the installed dependency.

Add a peer dependency

npm install --save-peer react

This adds the package to peerDependencies in package.json.

Run project scripts

npm run dev
npm run build
npm run test

These commands run scripts defined in package.json.

Run a local tool directly

npm exec -- eslint .

Use this when the tool is already available to the project and you want to run it directly instead of through a script.

Run a tool one time without adding it to the project

npx create-vite@latest my-app

This is common for project scaffolding and one-off commands.

Reproduce installs in CI

npm ci

Use this in CI and other automated environments when the repository already has a lockfile.

Progress

Quick checks

No quick checks in this lesson.

Mark lesson manually or answer quick checks to track progress.