Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Verdaccio - Host Your Own NPM Packages

This tutorial is for those of you who wish to develop and use NPM packages, but don't wish to share them with the rest of the world. It will show you how to set up a private Verdaccio server that will authenticate against a generated .htaccess file. However, in future I will show you how to authenticate against your private Gitlab server, but if your impatient, you can following this.


Create a docker-compose.yml file with the following content

version: '2.1'
    image: verdaccio/verdaccio:3.8
    container_name: verdaccio
    restart: always
      - "4873:4873"
        - "./volumes/verdaccio/storage:/verdaccio/storage"
        - "./volumes/verdaccio/conf:/verdaccio/conf"

Create the volumes:

mkdir -p $HOME/volumes/verdaccio/storage
mkdir -p $HOME/volumes/verdaccio/conf

Download the configuration file.

cd $HOME/volumes/verdaccio/conf

Create a htpasswd file in the same place (online tool). This will be the username and password you need to use when adding your registry later.

vim $HOME/volumes/verdaccio/conf/htpasswd

Install docker-compose if you haven't already.

Start Verdaccio through docker-compose:

docker-compose up

Your verdaccio server is now up. If you go the following address in your browser, you will see it, with some instructions on how to add a user, and to publish:

http://[IP or Domain]:4873

Testing - Create, Publish, and Install A Package

Skip this if you don't feel the need to test that your Verdaccio server is up and running. However, the commands here do show you the differences you need to make when trying to push/pull from your private repository instead of the default NPM one.

mkdir my-tiny-package
cd my-tiny-package

Create a package.json file within the folder with the following contents.

    "name": "@myCompanyName/my-tiny-package",
    "version": "1.0.0"

Authenticate against the registry with:

npm adduser --registry  http://[IP or Domain]:4873

Publish the package with:

npm publish --access=private --registry

Now when you want to install the package:

mkdir my-project
cd my-project
mkdir node_modules
npm install --registry @myCompanyName/my-tiny-package


Last updated: 28th December 2018
First published: 31st October 2018