Verdaccio is a lightweight, open-source package manager built on Node.js. It allows you to:
- Host your own packages: Store and manage your private packages, making it ideal for teams and organizations.
- Cache public packages: Speed up package installation by caching public packages from registries like npm.
- Create a proxy registry: Set up a proxy to access public packages while also hosting your private packages.
Verdaccio supports various package formats, including npm, yarn, and pnpm. Its simplicity, flexibility, and scalability make it a popular choice for managing packages in a local environment.
Key Features:
- Private package hosting
- Cache and proxy support
- Multi-protocol support (npm, yarn, pnpm)
- Web interface for easy package management
- Plugin architecture for customization
Use cases:
- Private package management for teams and organizations
- Offline package installation
- Local package caching for faster installation
- Custom package registries for specific use cases
Setting up a private npm registry using Verdaccio
Prerequisites
- Node.js (version 14 or higher)
- npm (version 6 or higher)
- Docker (optional)
Method 1: Global Installation
1) Install Verdaccio globally using npm:
npm install -g verdaccio
2) Start Verdaccio:
verdaccio
Method 2: Local Installation
1) Create a new directory for your Verdaccio instance:
mkdir verdaccio
cd verdaccio
2) Initialize a new npm project:
npm init -y
3) Install Verdaccio locally:
npm install verdaccio
4) Start Verdaccio
npx verdaccio
Method 3: Using Docker
1) Pull the official Verdaccio Docker Image:
docker pull verdaccio/verdaccio
2) Run the container:
docker run -d -p 4873:4873 verdaccio/verdaccio
Publish a package:
npm publish --registry http://<ip-address>:4873
To use it locally, set <ip-address> to localhost
Configure npm to use Verdaccio
Set Verdaccio as the registry for your npm client:
npm config set registry http://<ip-address>:4873
To use it locally, set <ip-address> to localhost
Alternatively, configure your specific project to use Verdaccio
Create a .npmrc file:
@xyz:registry=http://<ip-address>:4873
To use it locally, set <ip-address> to localhost
Install the packages:
npm install @xyz/shared-components-1
npm install @xyz/shared-components-2
Troubleshooting
Check the Verdaccio logs for errors: verdaccio logs
Verify that the storage directory has proper permissions.
Security Considerations
Use a secure password and consider enabling SSL/TLS encryption.
Limit access to your Verdaccio instance using a firewall or reverse proxy.