Sharing the code, libraries, or components between the members of a team or between teams sometimes needs to be private and the need of having a private npm registry is a very common thing these days.
There are a couple of solutions, but this article is dedicated to Verdaccio.
Verdaccio is a lightweight open-source private npm proxy registry and cache, that allows you to have your own npm registry for free.
The solution I want to share with you today is based on Verdacio installation with docker-compose.
I have set my private npm registry on Linux CentOS, but it can be set up on Windows or Mac OS
Let's create a docker-compose file, docker-compose.yml with the following content:
version: '2.1'
services:
verdaccio:
image: verdaccio/verdaccio:latest
restart: always
container_name: npm-registry
environment:
- VERDACCIO_PORT=4873
- VERDACCIO_PROTOCOL=https
ports:
- "4873:4873"
volumes:
- "/srv/npm/storage:/verdaccio/storage"
- "/srv/npm/config:/verdaccio/conf"
- "/srv/npm/ssl:/verdaccio/ssl"
volumes:
verdaccio:
driver: local
In my case I created the folder /srv/npm and subfolders /config, /storage, /ssl.
You might need to change the access permissions to these folders, so let's set it:
chmod -R 0777 /srv/npm
In the /srv/npm/config/config.yml file there some settings I would like to describe because at the moment when I installed my system the info I found was not very clear.
If you want to add a logo to the web you can set it in the config file:
web:
enable: true
title: NPM Registry - criscond.co.uk
logo: /verdaccio/conf/logo.png
primary_color: "#071e33"
gravatar: true
scope: "@myScope"
sort_packages: asc
sign:
expiresIn: 1d
if you want to set SSL you have to set in config the path to your SSL certificate and also to copy them to the SSL folder:
https:
key: /verdaccio/ssl/npm.hostname.com.key
cert: /verdaccio/ssl/npm.hostname.com.cert
ca: /verdaccio/ssl/npm.hostname.com.bundle
Change the working directory where the docker-comopse.yml file is and run the command below:
docker-compose up -d
That is all. Your private npm registry should be up and running.
I have created a repo on GitHub in case you need it and its URL is: https://github.com/criscond/verdaccio-docker
Happy coding!