Nov 6, 2019

Publish Angular 7 Library To Verdaccio Private Registry On Localhost

Publish Angular 7 Library To Verdaccio Private Registry On Localhost

Verdaccio is a free private npm proxy registry built in Node.js. So if you want to publish your Angular library in private registry to access only by your network then Verdaccio registry is the best option. I hope, This may help to beginners as explained all steps in very simple way.

Click here for more details (https://verdaccio.org/)

In this tutorial, I will just explain you the simple steps to publish your Angular 7 custom library on Verdaccio private registry. I am assuming you already created your Angualr 7 library, if not then please check below tutorial first.

How to create your first angular 7 library (link)

So lets start with Verdaccio private registry setup and configuration.

Step 1: Install Verdaccio
>> npm install -g verdaccio

Step 2: Install pm2, will require to start Verdaccio service

>>npm install pm2 -g

Step 3: Run Verdaccio in background using pm2

>> pm2 start /verdaccio bin file path

In my case on windows machine: pm2 start C:/Users/userName/AppData/Roaming/npm/node_modules/verdaccio/bin/verdaccio

Step 4: Set the verdaccio registry as a source. By default original NPM registry set.

>> npm set registry http://localhost:4873/
>> npm set ca null

Step 5: Registering a user in verdaccio registry

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

It will ask for username, password and valid email id to be entered. Make a note of this details that will use to login in verdaccio registry to publish our library.

Step 6: Go to angular workspace "libraryCollection"
>> cd libraryCollection

Step 7: Login into verdaccio registry. Enter the same username, password and email id set in Step 5.
>> npm login

Step 8: Go to /libraries/dist/your-library-name/your-library-name-0.0.1.tgz
>> cd libraries
>> cd dist
>> cd your-library-name

Step 9: Finally publish our library your-library-name-0.0.1.tgz on verdaccio registry

>> npm publish your-library-name-0.0.1.tgz

Now browse http://localhost:4873 and you will see new our library package there.

That's it. If you want to use your verdaccio library package from other Angular project then follow these steps.

Step 1: If you already have other angular application then go to root of that application or create new app using below commands.

>> ng new new-project

Step 2: Go to root of your new project and our library package from verdaccio registry.
>> cd new-project
>> npm install your-library-name

Step 3: Now we can import it in app.module.ts of new project

import { YourLibraryNameModule } from 'your-library-name';
@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    YourLibraryNameModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})

Step 4: Lets add our library selector tag "your-prefix-name-your-library-name" in app.component.html to display library component content.

Lets assume, your-prefix-name = webtechfunda and your-library-name = myfirstlib
then the tag will be like below.


Step 6: Run your new project by using below command and check output. you should see your library content on your new application page.

>> ng serve -o



Conclusion:

That's It Guys! At the time of writing (Nov 2019), I am not an Angular 7 expert but shared this knowledge with you whatever I experienced while learning. So if you have any opinions or suggestion related to this tutorial, Please feel free to comment and share your suggestions.


Check Recommended Articles:
How To Uninstall Verdaccio From Angular 7 Workspace
How to create your first angular 7 library

How To Uninstall Verdaccio From Angular 7 Workspace

How To Uninstall Verdaccio From Angular 7 Workspace

Step 1: Uninstall verdaccio from your machine
>> npm uninstall -g verdaccio

Step 2: Now set back npm registry as a default npm registry instead verdaccio regitry. Run this command.

>> npm set registry https://registry.npmjs.org // for HTTPS access

{or}

>> npm set registry http://registry.npmjs.org // for HTTP access


Conclusion:

That's It Guys! I loved to share my knowledge with you whatever I experienced while learning. If you have any opinions or suggestion related to this tutorial, Please feel free to comment and share your suggestions.


Check Recommended Articles:

How to create your first angular 7 library 
How To Publish Angular 7 Library To Verdaccio Private Registry On Localhost 
Free Verdaccio Private Registry Setup On AWS 

How To Create Your First Angular 7 Library

How-To-Create-Your-First-Angular-7-Library

In this article, we will see how to create a simple Angular 7 library step by steps. I will mainly focus on commands and configurations required for library. At the time of writing (Nov 2019), I am not an Angular 7 expert but still sharing this knowledge with you whatever I experienced while learning. I hope, This may help to beginners as explained all steps in very simple way.

If you want know in details please click here.(https://angular.io/guide/creating-libraries)

Step 1: Create an Angular Workspace with no initial application

>> ng new libraryCollection --create-application=false

Step 2: Go to newly created angular workspace "libraryCollection"

>> cd libraryCollection

Step 3: Create your first library by running below command.

>> ng generate library your-library-name --prefix your-prefix-name

Note your-library-name and your-prefix-name can be anything but make sure to use unique name, if in future you wanted to publish that on NPM or Verdaccio registry.

Once you done with Step 3, you will see your library "your-library-name" generated under directory "libraryCollection->projects->your-library-name" and below files generated in "src -> lib" directory.


  • your-library-name.component.spec.ts
  • your-library-name.component.ts
  • your-library-name.module.ts
  • your-library-name.service.spec.ts
  • your-library-name.service.ts


Also one very important file will get generated i.e public-api.ts. This file is the entry point of our library to declare what components, services or modules we want to export so that can be imported from other Angular applications.

Step 4: Now we will build library using below command
>> cd libraries
>> ng build your-library-name

Once you execute above command, it will generate a built in this directory path -> libraries\dist\your-library-name
That means you have successfully built your library.

Step 5: Lastly, it's time to create a package of our library so that we can use that package from other Angular projects. It will generate a tar file under directory -> libraries\dist\your-library-name\your-library-name-0.0.1.tgz

>> cd libraries\dist\your-library-name
>> npm pack pgondane-lib

That's it. If you want to use your library package then follow these steps.

Step 1: If you already have other angular application then go to root of that application or create new app using below commands.

>> ng new new-project

Step 2: Open new project new-project\package.json file, search for keyword "rxjs" and add below line above it.

Example: 

"your-library-name": "../libraries/dist/your-library-name/your-library-name-0.0.1.tgz",
"rxjs": "~6.4.0",

Step 3: Go to root of your new project and install our library package.
>> cd new-project
>> npm install your-library-name

Step 4: Now we can import it in app.module.ts of new project

import { YourLibraryNameModule } from 'your-library-name';
@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    YourLibraryNameModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})

Step 5: Lets add our library selector tag "your-prefix-name-your-library-name" in app.component.html to display library component content.

Lets assume, your-prefix-name = webtechfunda and your-library-name = myfirstlib
then the tag will be like below.



Step 6: Run your new project by using below command and check output. you should see your library content on your new application page.

>> ng serve -o

Conclusion:

That's It Guys! At the time of writing (June 2019), I am not an Angular 7 expert but shared this knowledge with you whatever I experienced while learning. So if you have any opinions or suggestion related to this tutorial, Please feel free to comment and share your suggestions.


Check Recommended Article:
How To Publish Angular 7 Library To Verdaccio Private Registry On Localhost

Free Verdaccio Private Registry Setup On AWS

Free Verdaccio Private Registry Setup On AWS

Verdaccio registry is a free private npm proxy registry which made in NodeJS. We can setup our private NPM application / libraries with free of cost. The benefit of this registry is privacy, only authorized persons can access this registry and can use published libraries or applications. I hope, This may help you to start learning and utilizing free Verdaccio private registry for your company, organization or individuals.

Click here for more details (https://verdaccio.org/)

In this tutorial, I will just explain you the simple steps to setup Verdaccio private registry on Amazon Web Services platform using EC2 service. I am assuming you already created EC2 Amazon Linux instance, if not then please check below tutorial first.

AWS CLI Commands For AWS EC2 (Amazon Elastic Compute Cloud) (https://tinyurl.com/y2ozksyc)

So lets start with Verdaccio private registry setup and configuration.

Step 1: Open SSH & Login in using your EC2 key.

Step 2: Install Node Version Manager (nvm) first

wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

Step 3: Install Node using Node Version Manager (nvm)

>> nvm install node

Step 4: Install Verdaccio & pm2, will require to run Verdaccio service in background

>> npm i -g verdaccio pm2

Step 5: Set the verdaccio registry as a source. By default original NPM registry set.
>> npm set registry http://localhost:4873
>> npm set ca null

Step 6: Run Verdaccio and stop it. It will create a config file we will use.

>> verdaccio

Step 7: Now do below configuration for listening to all addresses on that server machine / EC2 instance.

Click here for more details: https://github.com/verdaccio/verdaccio/blob/master/conf/full.yaml

Open and edit config.yaml file:

>> nano .config/verdaccio/config.yaml

Add below lines at the end. Click here for more details. https://github.com/verdaccio/verdaccio/blob/ff409ab7c05542a152100e3bc39cfadb36a8a080/conf/full.yaml#L113

listen:
  - 0.0.0.0:4873

Change below line so that only authenticated person can access our registry

Replace "access: $all" with "access: $authenticated"

There are some more parameters available to configure it. Like storage, proxy, default port change. Click here for more details. https://github.com/verdaccio/verdaccio/blob/ff409ab7c05542a152100e3bc39cfadb36a8a080/conf/full.yaml#L113

Step 8:Run Verdaccio in background using PM2:

pm2 start verdaccio

Step 9: Now, You can access your Verdaccio web UI.

The URL will look like something:

http://ec2-..compute.amazonaws.com:4873

{or}

http://your-ec2-public-ip-address:4873 (You can check your EC2 instance public ip from AWS console)

To confirm verdaccio running status, run the command below
>> pm2 list

Step 10: Registering a user in verdaccio registry

>> npm set always-auth true
>> npm adduser

It will ask for username, password and valid email id to be entered. Make a note of this details that will use later to login in verdaccio registry to publish our library.


Step 11: Now we are ready to use our AWS server instance work as a private registry.

Login into verdaccio registry. Enter the same username, password and email id set in above Step.

>> npm set registry http://your-ec2-public-ip-address:4873
>> npm login

Step 12: Go to your custom library package path. In my case this is my Angular 7 package path -> /libraries/dist/your-library-name/your-library-name-0.0.1.tgz

If you like to know how to create angular 7 library/package then click here (link)

>> cd [custom library package path]

Step 9: Finally publish our library your-library-name-0.0.1.tgz on verdaccio registry

[custom library package path] >> npm publish your-library-name-0.0.1.tgz

{or}

[custom library package path] >> npm publish

{or}

[custom library package path] >> npm publish --registry http://your-ec2-public-ip-address:4873

Now browse http://your-ec2-public-ip-address:4873 and you will see new our library package there.


Conclusion:

That's It Guys! I loved to share my knowledge with you whatever I experienced while learning. If you have any opinions or suggestion related to this tutorial, Please feel free to comment and share your suggestions.


Check Recommended Articles:

How to create your first angular 7 library 
How To Publish Angular 7 Library To Verdaccio Private Registry On Localhost 
How To Uninstall Verdaccio From Angular 7 Workspace