How to Publish Custom NPM Packages to a Private Local Registry Using Verdaccio on Docker

Erman Enginler
HAVELSAN
Published in
4 min readJan 29, 2024

In this article we are going to learn how to publish our custom npm packages that we create during development process of a project to our local test repo using Verdaccio on Docker

If you are developing custom components in a project at some point you have to test published npm packages without sending it to public repo. You may use a local repo hosted in your computer to develop concurrently as you update packages without increasing version in public repo. Today we will learn how to achieve this.

At the time I wrote this article I use:
node v18.19.0
npm v10.2.3
Verdaccio v5.x
Docker Desktop v4.26.1
Git v2.43.0.windows.1
Visual Studio Code 1.85.2

First we need to run Verdaccio over Docker.

Clone or download this project into a place where you want your local npm storage will be served.

In my example I will use C:\Projects\verdacio-local so navigate to C:\Projects and run

git clone https://github.com/ermaneng/verdaccio-local.git

This command will clone all the files we need for composing docker container.

Your project folder should look like

Open a terminal in VS Code and run

docker-compose up

at the root of the project. You should see some output like below.

Note: It may prompt you to create filesharing for folders during compose up.

After docker compose finishes. Check File Sharing setting under Docker/Settings/Resources . If docker-compose up fails add paths to File sharing as seen below and try again.

If docker-compose up goes well you should see docker container is running on dashboard

Now open your browser and navigate to http://localhost:4873 You should see Verdaccio is up and running like below.

Now we have Verdaccio running on Docker. So how can we publish a package to Verdaccio.

First open a terminal and run

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

This will prompt you to enter username, password and email. You will use these credentials to LOGIN to your local Verdaccio repo and see your packages.

To publish your package go to your package folder ready for publishing and run

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

I will use my dummy package named ee-sayac to demonstrate publishing sequence. If all goes well you should see publish output as below

After that navigate to http://localhost:4873 again now you will see your custom package.

Now we have a private repo running on local docker.

So how do we use that package in a project?

To use it add an .npmrc file on your consumer project root and point registry to http://localhost:4873

Then when you start npm install it will install packages from local repo.

Additional notes for verdaccio-local

  • You may find your published packages physically at storage folder inside verdaccio-local folder.
  • Your verdaccio user ceredentials are stored in verdaccio-local/conf/htpasswd
    You may delete this file to create new user or generate a htpasswd file using this.
  • You may change config in conf/config.yaml for your needs. For example: for this article max user is set to 1 and access is set to $all. You may check Configuration File | Verdaccio

That’s all. Please like.

You may download the sample project on GitHub
ermaneng/verdaccio-local: Local Verdaccio Docker (github.com)

Good readings
ermaneng

--

--