A
AiTechWorlds
AiTechWorlds
Install, update, publish, workspaces, semver, scripts, .npmrc configuration every npm and Yarn command you need.

| Feature | npm | Yarn (Berry) | pnpm |
|---|---|---|---|
| Lock file | package lock.json | yarn.lock | pnpm lock.yaml |
| Install speed | Moderate | Fast | Fastest |
| Disk usage | Duplicates in each project | Duplicates | Content addressed store (shared) |
| Workspaces | Yes | Yes | Yes |
| Plug'n'Play | No | Yes (optional) | No |
| Default in Node.js | Yes | No | No |
# npm
npm init # interactive prompts
npm init -y # accept all defaults
# Yarn
yarn init
yarn init -y# npm
npm install # install all from package.json
npm install lodash # add runtime dependency
npm install --save-dev jest # add dev dependency
npm install -D typescript # shorthand for --save-dev
npm install -g nodemon # global install
npm install lodash@4.17.21 # specific version
npm install lodash@^4.0.0 # semver range
# Yarn
yarn # install all
yarn add lodash # add runtime
yarn add --dev jest # add dev dependency
yarn add -D typescript # shorthand
yarn global add nodemon # global
yarn add lodash@4.17.21 # specific versionnpm uninstall lodash
npm uninstall --save-dev jest
npm uninstall -g nodemon
yarn remove lodash# npm
npm update # update all (respects semver range)
npm update lodash # update specific package
npm outdated # list outdated packages
npx npm-check-updates -u # upgrade all to latest (ignores semver)
# Yarn
yarn upgrade # update all
yarn upgrade lodash # update specific
yarn upgrade lodash --latest # update to latest (ignore semver)
yarn outdated # list outdated# package.json scripts:
# "scripts": { "build": "tsc", "test": "jest", "dev": "ts-node src/index.ts" }
npm run build
npm run test
npm test # shorthand for npm run test
npm start # shorthand for npm run start
yarn build
yarn test
yarn dev
# npm โ pass arguments to scripts
npm run test -- --watch
npm run build -- --mode production| Notation | Meaning | Example Range |
|---|---|---|
1.2.3 | Exact version | Only 1.2.3 |
^1.2.3 | Compatible (no major bump) | >=1.2.3 <2.0.0 |
~1.2.3 | Patch level (no minor bump) | >=1.2.3 <1.3.0 |
>=1.2.3 | Minimum version | Any version โฅ1.2.3 |
* | Any version | Latest |
1.x | Any patch/minor | 1.0.0 1.999.999 |
npm list # all installed packages
npm list --depth=0 # top-level only
npm list lodash # check if installed
npm info lodash # registry info
npm info lodash versions # all published versions
yarn list
yarn list --depth=0
yarn info lodash// package.json (root)
{
"name": "my-monorepo",
"private": true,
"workspaces": ["packages/*", "apps/*"]
}# npm workspaces
npm install # install all workspaces
npm install lodash -w packages/utils # install in specific workspace
npm run build -w packages/core # run script in workspace
npm run build --workspaces # run in all workspaces
# Yarn workspaces
yarn workspaces run build # run build in all workspaces
yarn workspace packages/utils add axios# Login
npm login
npm whoami # verify logged in
# Publish
npm publish # publish (uses version in package.json)
npm publish --access public # for scoped packages (@user/pkg)
npm version patch # 1.0.0 โ 1.0.1
npm version minor # 1.0.0 โ 1.1.0
npm version major # 1.0.0 โ 2.0.0
npm deprecate my-pkg@1.0.0 "Use v2"
# Dry run
npm publish --dry-runnpx create-react-app my-app # run without installing globally
npx create-next-app@latest my-app
npx tsc --init # TypeScript config
npx prettier --write . # format codebase
npx eslint --fix src/ # lint and fix
npx npm-check-updates # check for updates without changing files# .npmrc (project or global ~/.npmrc)
registry=https://registry.npmjs.org/
save-exact=true # pin exact versions (no ^ or ~)
engine-strict=true # fail if Node version doesn't match engines field
fund=false # suppress funding messages
audit=false # skip audit on install (CI speed)| Rule | Reason |
|---|---|
| Commit lock files | Reproducible installs for all team members |
| Never edit lock files manually | Auto regenerated; manual edits cause corruption |
Run npm ci in CI/CD | Installs exact versions from lock file, faster |
| Delete and regenerate periodically | Cleans up orphaned entries |
npm ci # clean install from lock file (CI/CD standard)
npm install # can update lock file; developer workflownpm install in CI instead of npm ci can silently update packages, breaking reproducibilitynode_modules/ it belongs in .gitignore, not source control^ (caret) for production dependencies without testing updates a minor semver bump can break APIsnpm install without --omit=dev) bloats images and install timeGet more notes like this daily on Telegram!
Free study notes, cheat sheets & AI tips
Last reviewed on June 13, 2026 by the AiTechWorlds Notes Team. Free cheat sheet no signup required.
Join AiTechWorlds on Telegram and get daily AI tips, prompt engineering templates, coding resources, and exclusive content 100% free!
No spam. Leave anytime.