
If you want to publish your own private javascript packages, you have a number of registries to select. Some of them are as follows,
- npmjs.com private registry
- Hakuna.cloud
- Packagecloud.io
- Gemfury.com
- Verdaccio.org Etc.
If you are working with Azure DevOps, the most attractive way of setting up a private npm registry is using Azure DevOps Artifacts. This article is focused on how to create a private feed and publish your npm package there.
Before starting the work, we should learn a little bit about .npmrc file. 😊
What is .npmrc?
This file is a configuration file for NPM, it defines the settings on how NPM should behave when running commands. When working locally in a project, a .npmrc file in the root of the project (near to node_modules and package.json) will set config values specific to this project.
Note that this only applies to the root of the project that you’re running npm in. If you define a registry inside .npmrc in your root folder, it affects only to your project.
This .npmrc file should contain credentials for all of the registries that you need to connect to.
Let’s start the journey!! 🙂
First of all, let’s create a new feed.
Step 01: Create a Feed
Go to Azure Artifacts
Select +New feed

Then,
- Give the feed a name
- Choose who can read and contribute packages in your feed
- Choose the upstream sources for your feed
- select
Create

Why Upstreams?
If you want to use both private packages you’ve created and public packages from npmjs.com, the recommended way is using upstream sources. The npmjs.com upstream source allows you to merge the contents of npmjs.com into your feed such that the npm client can install packages from both locations. Enabling upstream sources also automatically enables the saving of packages you use from the upstream source.
Step 02: Connect to feed
Select Connect to feed
Select npm from the panel.

Now copy the content under Add this feed to your project .npmrc and paste it into your .npmrc
This defines the location of our npm registry. Now you need to generate credentials for your feed and save it in .npmrc file.
Just click on Generate npm credentials button and it will generate a set of credentials for your private feed. Simply copy the content under Add credentials to your user .npmrc manually and paste it also in .npmrc.
Now you are ready to install private npm packages from your Azure DevOps npm registry. Please make sure you have enabled npmjs.com as upstreams in Azure DevOps Artifacts to allow access to other public npm packages.
How to publish an npm package into my private npm registry?
It is really easy if you go through the following simple steps.
Go inside the root folder of the Javascript project that you want to publish.
Create an empty .npmrc file and add the registry and credentials as Step 03. (If you have created the file already, you can copy and paste the same .npmrc file)
Open command prompt inside root folder
npm publishIt directly publishes into your Azure DevOps private registry. 😀
