NPM (Node Package Manager)
NPM is the default package manager for Node.js and the world's largest software registry. It allows developers to install, share, and manage dependencies in their projects.
Key Features
Package Installation Install libraries and tools with simple commands.
Version Management Specify and lock dependency versions.
Script Running Define and run custom scripts.
Publishing Share your own packages with the community.
Common Commands
bash# Initialize new project npm init # Install dependency npm install react # Install dev dependency npm install --save-dev eslint # Install globally npm install -g typescript # Update packages npm update # Run script npm run build # Uninstall package npm uninstall lodash
package.json
Central file managing project metadata and dependencies:
json{ "name": "my-project", "version": "1.0.0", "scripts": { "dev": "vite", "build": "vite build", "test": "vitest" }, "dependencies": { "react": "^18.2.0" }, "devDependencies": { "vite": "^5.0.0" } }
package-lock.json
Locks exact versions of all dependencies for consistent installs across environments.
Alternatives
- Yarn: Faster alternative with improved dependency resolution
- pnpm: Efficient package manager using hard links