Open In App

How to Set Up a Private NPM Registry using Verdaccio ?

Creating a private NPM registry locally can significantly improve your Node.js development workflow by providing a secure environment for managing proprietary packages. In this guide, we’ll walk through the process of setting up your own private NPM registry using Verdaccio, a popular choice among developers for its ease of use and flexibility.

Prerequisites:

Before you begin, make sure you have the following prerequisites installed on your system:



This guide will cover the following steps to help you set up a private NPM registry locally:

Why Set Up a Private NPM Registry?

Public npm registries serve as a rich source of open-source packages, but there are several reasons organizations opt for a private registry:

  1. Control and Security: Maintain control over the packages used within your organization, ensuring compliance with security policies and minimizing the risk of using vulnerable dependencies.
  2. Privacy: Keep proprietary or sensitive code within the confines of your organization’s network, preventing exposure to the public.
  3. Performance: Reduce reliance on external networks by hosting packages locally, leading to faster installation and fewer network-related issues.
  4. Customization: Customizing the registry to meet your organization’s specific needs, including custom packages, access controls, and integration with existing infrastructure.

Example

Publishing a Package to Your Local Registry

Step 1: Run the following command to install:

npm install -g verdaccio

Step 2: Run verdaccio using:



verdaccio

Step 3: Run the following commands in your terminal:

npm login --registry=http://localhost:4873

Step 4: Enter your Verdaccio credentials when prompted.

npm publish --registry=http://localhost:4873

Step 5: Installing a Package from Your Local Registry

To install a package from your local registry, use the following command:

npm install <package-name> --registry=http://localhost:4873

Step 5: Configuring npm to Use Your Local Registry by Default

Set your default registry to your local registry by running:

npm config set registry http://localhost:4873

By following this comprehensive guide, you’ll be able to set up your own private NPM registry locally using Verdaccio.

Article Tags :