Node Package Manager
"npm is a package manager for the JavaScript programming language. It is the default package manager for the JavaScript runtime environment Node.js. It consists of a command line client, also called npm, and an online database of public and paid-for private packages, called the npm registry.", Wikipedia
Lesser Known / Used NPM Commands
Init
npm init -y
View / Show
Shows you the registry information on a given package, e.g.
npm view react
Listing
Listing all globally installed packages...
npm list -g --depth=0
Setting Python Version
Setting a version of python to use during installation of packages
npm config set python python2.7
Linking
npm link [package-name]
"Symlink a package folder" "Sometimes you need to work on application code and a dependency at the same time."
cd ~/projects/node-redis # go into the package directory
npm link # creates global link
cd ~/projects/node-bloggy # go into some other package directory.
npm link redis # link-install the package
More here.
"To kill the link, go back to your local version and at root type npm unlink --no-save moment. Then run npm install."
Publishing
"Publishes a package to the registry so that it can be installed by name. All files in the package directory are included if no local .gitignore or .npmignore file exists."
npm publish
Logging in to NPM before publishing. Note that you can check to see if you're logged in (and as who) with npm whoami
.
npm login
Utilities
- unpkg - The CDN for everything on npm
Alternatives
Shrinkwrap
"This command repurposes package-lock.json into a publishable npm-shrinkwrap.json or simply creates a new one"
npm shrinkwrap
Audit
"...submits a description of the dependencies configured in your project to your default registry and asks for a report of known vulnerabilities"
npm audit