Skip to main content
TellaDev
Cheatsheets npm / yarn

25 entries

npm / yarn

npm and yarn commands for managing packages, running scripts, and publishing

25 commands

npm install
Install all dependencies listed in package.json. Yarn equivalent: yarn
npm install
npm install <pkg>
Install a package and save it to dependencies. Yarn equivalent: yarn add <pkg>
npm install express
npm install -D <pkg>
Install a package as a dev dependency. Yarn equivalent: yarn add -D <pkg>
npm install -D vitest
npm install -g <pkg>
Install a package globally. Yarn equivalent: yarn global add <pkg>
npm install -g typescript
npm ci
Clean install from package-lock.json (faster, for CI environments). Yarn equivalent: yarn install --frozen-lockfile
npm ci
npm update
Update all packages to their latest compatible versions. Yarn equivalent: yarn upgrade
npm update lodash
npm run <script>
Run a script defined in the scripts field of package.json. Yarn equivalent: yarn <script>
npm run build
npm run dev
Run the dev script (commonly starts a development server). Yarn equivalent: yarn dev
npm run dev
npm run build
Run the build script to compile/bundle the project. Yarn equivalent: yarn build
npm run build
npm test
Run the test script. Yarn equivalent: yarn test
npm test
npm run lint
Run the lint script. Yarn equivalent: yarn lint
npm run lint -- --fix
npx <cmd>
Execute a package binary without installing it globally. Yarn equivalent: yarn dlx <cmd>
npx create-next-app my-app
npm uninstall <pkg>
Remove a package from the project. Yarn equivalent: yarn remove <pkg>
npm uninstall moment
npm list
List installed packages in the current project. Yarn equivalent: yarn list
npm list --depth=0
npm outdated
Show packages that are out of date. Yarn equivalent: yarn outdated
npm outdated
npm audit
Scan for security vulnerabilities in installed packages. Yarn equivalent: yarn audit
npm audit
npm audit fix
Automatically fix vulnerabilities where possible. Yarn equivalent: yarn audit --fix (limited)
npm audit fix
npm dedupe
Reduce duplication by flattening the dependency tree
npm dedupe
npm publish
Publish the current package to the npm registry. Yarn equivalent: yarn publish
npm publish --access public
npm version patch
Bump the patch version (e.g., 1.0.0 → 1.0.1) and create a git tag. Yarn equivalent: yarn version --patch
npm version patch
npm version minor
Bump the minor version (e.g., 1.0.0 → 1.1.0). Yarn equivalent: yarn version --minor
npm version minor
npm pack
Create a tarball (.tgz) of the package for local testing before publishing
npm pack
npm config set registry <url>
Set the npm registry URL (e.g., for a private registry)
npm config set registry https://registry.npmjs.org
npm config get prefix
Get the global installation prefix (where global packages are stored)
npm config get prefix
npm init -y
Initialize a new package.json with default values. Yarn equivalent: yarn init -y
npm init -y