Catalog / NPM Cheatsheet
NPM Cheatsheet
A comprehensive cheat sheet for Node Package Manager (NPM), covering essential commands and functionalities for managing JavaScript packages and dependencies.
Basic NPM Commands
Installation
|
Installs all dependencies defined in
|
|
Installs a specific package and adds it as a dependency to
|
|
Installs a package as a development dependency. Useful for tools like testing frameworks.
|
|
Installs a package globally, making it available in the system’s PATH. Often used for command-line tools.
|
|
Install a package directly from a git repository.
|
|
Install dependencies with a clean slate, based on
|
Updating Packages
|
Updates all packages listed in
|
|
Updates a specific package to the latest version that satisfies its version range.
|
|
Attempts to automatically fix known security vulnerabilities in your dependencies.
|
|
Lists outdated packages.
|
Uninstalling Packages
|
Uninstalls a package from the
|
|
Uninstalls a package from development dependencies.
|
|
Uninstalls a globally installed package.
|
|
Remove
|
Managing Dependencies
Package Information
|
Displays detailed information about a package from the npm registry.
|
|
Shows the latest version of a specific package.
|
|
Lists the dependencies of a specific package.
|
|
Lists installed packages and their dependencies in a tree structure.
|
Working with package.json
|
Guides you through creating a new
|
|
Creates a
|
|
Installs only production dependencies (excluding devDependencies) from
|
|
Removes extraneous packages. If the
|
Scripts
|
Executes a script defined in the
|
|
Runs the
|
|
Runs the
|
|
Runs the
|
|
Runs the
|
Advanced NPM Usage
Publishing Packages
|
Logs you into the npm registry using your credentials.
|
|
Publishes the package in the current directory to the npm registry. Make sure to increment the version number in
|
|
Removes a published package from the npm registry. Use with caution!
|
|
Adds a user as an owner of a package, allowing them to manage the package.
|
Managing Cache
|
Clears the npm cache. Use with caution, as it can sometimes resolve installation issues.
|
|
Verifies the integrity of the cache and cleans up corrupted data.
|
|
Gets the cache location.
|
NPM Configuration
|
Displays the current npm configuration.
|
|
Retrieves the value of a specific configuration key.
|
|
Sets a configuration key to a specific value.
|
|
Deletes a configuration key.
|
NPM Versioning and Security
Semantic Versioning
NPM uses semantic versioning (semver) to manage package versions.
|
Examples of version ranges:
|
Security Audits
|
Analyzes your project’s dependencies for security vulnerabilities and provides a report.
|
|
Attempts to automatically fix the detected security vulnerabilities by updating to secure versions of the dependencies.
|
|
Attempts to automatically fix the detected security vulnerabilities by updating to secure versions of the dependencies with force.
|
Bumping Versions
|
Sets the package version to a specific version number.
|
|
Increments the major version number.
|
|
Increments the minor version number.
|
|
Increments the patch version number.
|
|
Increments the pre-release version number.
|