0% found this document useful (0 votes)
136 views2 pages

NPM Cli - Commands and Flags

npm is a command line interface for managing Node.js packages. It allows users to [1] initialize new projects, [2] install dependencies, [3] publish packages, and [4] run scripts. Common commands include npm install to add packages, npm start to run scripts like a development server, and npm publish to release a package. It also provides utilities for working with dependencies, checking for outdated packages, and running security audits.

Uploaded by

sahra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
136 views2 pages

NPM Cli - Commands and Flags

npm is a command line interface for managing Node.js packages. It allows users to [1] initialize new projects, [2] install dependencies, [3] publish packages, and [4] run scripts. Common commands include npm install to add packages, npm start to run scripts like a development server, and npm publish to release a package. It also provides utilities for working with dependencies, checking for outdated packages, and running security audits.

Uploaded by

sahra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

CHEAT SHEET

developers.redhat.com | @RHDevelopers

NPM CLI - Commands and Flags

This cheat sheet covers the most common and helpful commands and ags for the npm CLI.

BASIC USAGE

-v, --version npm ls


Prints the current version of npm you are using Lists the installed modules
<command> -h, --help npm prune
Quick help on the speci ed command Removes any extraneous modules
-l npm link
Displays full usage info Symlinks a package folder
npx [command]
Runs an arbitrary command from an npm module (either one NPM SCRIPTS
installed locally, or fetched remotely)
npm start

CREATE A NEW NODE.JS APPLICATION Runs a prede ned command speci ed in the start property of a
package’s scripts object
npm init [--yes|-y|--scope]
npm run [script]:: Runs a prede ned command speci ed in the [script]
Initializes a new Node.js project, creates a package.json le property of package’s scripts object

--yes, -y Skips the init questionnaire PUBLISH A NODE MODULE


Creates a scoped
--scope
application/module npm whoami
Displays the npm username
INSTALL NODE MODULES
npm login

npm install <module_name> Login to the registry

Installs the specifed module as a dependency npm version [options]


Bumps the version of a module
Installs the specifed module as a development
--save-dev
dependecy Bumps the version to the <newversion>. ex: npm
<newversion>
-g Installs the module globally version 1.1.0
Bumps the major version by 1. ex: npm version
npm install [--production] major
major output: v2.1.0
Installs the modules speci ed in the package.json. The --production Bumps the minor verison by 1. ex: npm version
minor
ag will not install development dependencies minor output v1.2.0
npm ci Bumps the patch version by 1. ex: npm version
patch
patch output: v1.1.1
Similar to npm install, but for use in automated environments such
as test platforms, continuous integration, and deployment Bumps the major version by 1, but as a prerelease.
premajor
ex: npm verison premajor output: v2.1.0-0
npm uninstall <module>
Bumps the minor version by 1, but as a prerelease.
Removes a module preminor
ex: npm verison preminor output: v1.2.0-0
npm outdated Bumps the patch version by 1, but as a prerelease.
prepatch
Checks for outdated modules ex: npm verison prepatch output: v1.1.1-0
Bumps the prerelease version. ex: npm version
npm update prerelease
prerelease output: 1.1.0-1
Updates modules to the latest version, respecting semver --preid= Uses a custom prerelease id tag. ex: npm version
CHEAT SHEET
developers.redhat.com | @RHDevelopers

<prerelease-id> prelease --preid=beta example output: 1.1.0-beta.0


MISC
from-git Uses the latest git tag as the version
npm audit
npm shrinkwrap
Runs a security audit
Locks down dependency versions for publication
npm bugs
npm publish [--dry-run]
Bugs for a module in a web browser
Publishs a module. Uses the --dry-run ag to get a preview of what
will be published npm docs
npm deprecate Docs for a module in a web browser
Deprecates a version of a module npm fund

npm unpublish Retrieves funding information


Removes a module from the registry
npm dist-tag
Modi es package distribution tags
npm logout
Logs out of the registry

You might also like