npm basics
Installation
npm comes pre-installed with Node.js. To check if you have npm installed:
To update npm to the latest version:
Initializing a Project
For a quick start with default values:
Installing Packages
Install a package and add to dependencies
Install a package and add to devDependencies
Install a specific version of a package
Install packages globally
Uninstalling Packages
To remove from devDependencies:
To uninstall a global package:
Updating Packages
To update all packages in package.json:
To update a specific package:
Listing Packages
List installed packages:
List global packages:
Running Scripts
Run a script defined in package.json:
Common built-in scripts:
Managing the package.json File
View package.json contents:
Set a config option:
Get a config option:
Publishing Packages
Login to npm:
Publish a package:
Versioning
Increment version and create a git tag:
Auditing for Vulnerabilities
To automatically fix vulnerabilities:
Clearing npm Cache
Viewing Package Information
To view all versions of a package:
Remember to always keep your npm and Node.js versions up to date, and regularly audit your projects for potential security vulnerabilities. The npm ecosystem is vast and constantly evolving, so staying informed about best practices and new features is crucial for efficient package management.