---
title: "How to Publish My Angular Library in Private NPM with Verdaccio"
date: "2024-03-28"
slug: "how-to-publish-my-angular-library-in-private-npm-with-verdaccio"
author: "Dany Paredes"
canonical: "https://danywalls.com/how-to-publish-my-angular-library-in-private-npm-with-verdaccio"
description: "When working with libraries, we aim to share our code with teammates, not just keep it on our own computers. The easiest way to share and test our code is by using npm pack to create a zip version. Another option is to publish our package is with azu..."
---

When working with libraries, we aim to share our code with teammates, not just keep it on our own computers. The easiest way to share and test our code is by using `npm pack` to create a zip version.

Another option is to publish our package is with azure artifacts, npm with free version public. But if we want to make it private, we need to pay or set up our own private npm repository. in this moment is where [Verdaccio](https://verdaccio.org/) comes in to help us.

## What is Verdaccio

Verdaccio allows us to register our libraries locally with ease, using a nice web interface that supports NPM, YARN, and PNPM. It also works as a proxy for NPM, so when we request a library, it can first look in Verdaccio (with a small configuration) before checking NPM, acting as a local cache for our libraries.

## How its works ?

Verdaccio is a npm package but also with a docker image, in my case I run the npm version to make easy the example.

First install the verdaccio package:

```bash
npm i verdaccio
```

![](/images/posts/how-to-publish-my-angular-library-in-private-npm-with-verdaccio/b322d0d5-6965-4_78189.gif)

After install, we can run the command `verdaccio` it start the local repository server.

![](/images/posts/how-to-publish-my-angular-library-in-private-npm-with-verdaccio/4d22da86-f5ad-4_78189.png)

Go to the url, it provide the next step to finalize the configuration.

![](/images/posts/how-to-publish-my-angular-library-in-private-npm-with-verdaccio/86edac66-87f6-4_78190.png)

In another terminal, create the user by running the command

```bash
npm adduser --registry http://localhost:4873/
```

![](/images/posts/how-to-publish-my-angular-library-in-private-npm-with-verdaccio/34d0150a-5529-4_78190.gif)

We have ready our verdaccio, the final step is to publish our first library.

## Create and Publish

Before using Verdaccio, create an example library like `donweb-ui`. Set up the workspace, generate, and build the library.

Create the workspace example:

```bash
ng new my-company --create-application=false
```

Generate and build the library to generate from the terminal:

```bash
ng g library donweb-ui
ng build donweb-ui
```

After creating your library and building it, for example, my library, navigate to the `dist/donweb-ui` directory and execute the command `$ npm publish --registry` [`http://localhost:4873/`](http://localhost:4873/) to publish your library to Verdaccio.

```bash
$ npm publish --registry http://localhost:4873/
```

The result in your terminal looks like this:

![](/images/posts/how-to-publish-my-angular-library-in-private-npm-with-verdaccio/43edb723-b2d6-4_78190.gif)

After finishing, we can visit the [Verdaccio web](https://verdaccio.org/) interface to see our package, complete with all its details and the version available for installation.

![](/images/posts/how-to-publish-my-angular-library-in-private-npm-with-verdaccio/3f674f4f-d4d1-4_78190.gif)

## Getting Package For Verdaccio

If we try to install the version of our library, for example, `npm install donweb-ui@0.0.14`, we get an error. But why?

![](/images/posts/how-to-publish-my-angular-library-in-private-npm-with-verdaccio/9bb31e18-fece-4_78190.png)

By default, npm looks for packages in the npm repository. To direct npm to use the Verdaccio npm proxy, add a `.npmrc` file with the Verdaccio URL. Place this file at the same level as the `package.json` and try installing the library again.

![](/images/posts/how-to-publish-my-angular-library-in-private-npm-with-verdaccio/0ef4499b-9c8e-4_78190.gif)

It works! We installed our library from Verdaccio! 🥳

## Recap

Today, we learned that Verdaccio allows us to create our own npm registry easily, avoiding the complexity and costs associated with options like Azure Artifacts or npm's private version. Although Azure Artifacts has many features, Verdaccio is perfect for simple and direct scenarios.

Happy publishing!!

