In this final lesson, we will see how can we Publish Angular Library To Public NPM Repository which we created with the npm pack command.
The first thing will do is we have to signup for an account with npmjs for publishing the angular library to the pubic npm repository.
Provide your credentials by running the below mention command from the terminal.
(Note: This is a one-time operation only and you can skip this step if you have already logged in.)
Once you are logged in, we have to navigate to the dist folder of the application and then inside the library folder where we have created the news-twentyfour-0.0.1.tgz file using npm pack command.
publish library using below command:
npm publish - -access public
Then we can see the published package on npm at this URL:https://www.npmjs.com/package/< library- name>
Now as we have created and published our library to the public NPM repository we can install it anywhere in angular projects.
npm install — save <library-name>@0.0.1
(here 0.0.1 is the version number of a library, which is necessary)
As a good programming practice, we should have some unique names for the library we create.
Because our npm’s public registry will sure have many packages with these similar names. So you can follow the approach to add your npm’s username with your library name so that it can be uniquely identified and also to avoid the errors while you publish it.