Why Private Npm Registries Matter and How Verdaccio Makes It Easy

Hero Image

Why private npm registries matter

Most developers really only write a fraction of the code that powers their applications. The rest of it is leveraged through public, freely available, and mostly open source libraries through tools such as npm and Yarn.

The npm package ecosystem itself has over 1.3 million packages and powers thousands of applications on the internet. This availability of high-quality and well-maintained packages has been critical in helping companies and their developers move fast while focusing exclusively on the code related to the core business problem they are solving.

There is also a certain amount of risk associated with relying directly on libraries that companies lack direct control over. Additionally, for teams with larger codebases and diversified product lines, they will write libraries for internal use that they don’t want exposed to the public.

Having a private npm registry addresses these concerns and this is why Fusebit also offers a private package registry for all our customers and their integrations, out of box.

However, there are also other open source tools out there, like Verdaccio, that are playing a large role in making it easy to set one up and get started.

With Verdaccio, you’re able to:

  • Use private packages to protect your internal libraries from public exposure
  • Cache your registry to speed up build times and limit exposure from upstream changes
  • Link multiple registries from different sources and consolidate them into one single endpoint

It also comes with a sleek web interface to help manage your packages and has built-in authentication that provides the ability to allow and restrict access to packages and scoped packages as needed.

Getting Started with Verdaccio

To get started, install it directly from npm with:

npm install -g verdaccio

Once installed, you can fire it up with the following CLI Command:

verdaccio

The default installation uses port 4873, but you can change the port by using:

verdaccio --listen 5000

The installation will create a default configuration file that leverages a local database and basic authentication. However, you can modify this file to:

  • Change storage location of your packages
  • Define the plugins directory to extend Verdaccio
  • Modify the proxy settings
  • Define package access control settings
  • Set your uplinks that will be used as fallback if packages aren’t available locally

Once set up, you will need to add a new user before you can publish. You will be asked to set up a new user with a login and password along with an email address.

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

This will also automatically log you into Verdaccio with the newly created user and use those credentials when you deploy your package as well.

Deploying your Packages to the Registry

Next, you will want to publish your package to the registry. For the purposes of demonstration, we’ll walk you through setting this up with an example package called ‘verdaccio-fusebit’.

First, create a new directory called ‘verdacio-fusebit’ and initialize a new npm directory using:

npm init -f

This will create the following json:

{
  "name": "verdaccio-fusebit",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

Next, in your directory, create a new file called index.js which contains your module. It can even be something as simple as this Hello World function:

function helloWorld() {
console.log ("Hello world from Fusebit!")
}

module.exports = helloWorld;

Finally, you can publish to your registry by running:

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

NOTE: Make sure that you bump your package number everytime you publish, otherwise it won’t let you publish.

Head over to http://localhost:4873, and you will be able to see your newly published package!

Verdaccio Package

To access and install your new package in any project, simply use:

npm install --registry http://localhost:4873 verdaccio-fusebit

If you want to set this registry as your default so you don’t have to pass in the registry flag everytime, you can do this through:

npm set registry http://localhost:4873/

Deploying to the Cloud

Verdaccio has support for AWS, Kubernetes, and Docker so you can easily deploy your registry to the cloud and scale quickly. To learn more about how to do this and integrate directly with your CI tools, go to verdaccio.org.

Follow @fusebitio on Twitter for more developer-focused content including developer tools, APIs, and integrations.


ArrowPrevious
NextArrow

Most Recent

19 May 2022
How to Use the Gmail API in Node.js - A Step-by-Step Tutorial

Follow this guide to setting up and using Gmail API in Node.js to read, drafts, and send emails.

19 May 2022
Create Your First Node.js GitHub Action, a How-To Guide

In this post, you'll learn what GitHub Actions are and how to create your first GitHub Action for your Node.js application.

17 May 2022
New Express 5 Features to Try

Express.js 5 is currently in Beta. In this article, we will cover the new Express.js 5 features and why Node.js developers should try them out.