Create Your First NPM package using Angular
Harshal S.
Micro Frontend Consultant | Certified Angular Developer | ?? JavaScript | ?? with Angular | PUCSDIAN ?????1??5??
NPM:- ( Node Package Manager). NPM is the package manager for the Node JavaScript platform.?It puts modules in place so that Node can find them, and manages dependency conflicts. It is used to publish, discover, install, and develop node programs.
How to create Node Package Using Angular
?1) Make sure you have an NPM account if not check it out here https://www.npmjs.com/
?2) First we have to create an angular project using the command ng g new project_name?
?3) Then we have to create an angular library for which we have to create package in this example I have created a simple button package. We have to use create library command?ng g library button
?4) After creating the library we can see another project folder created in our project directory which is having its own angular configuration.
?5) We can verify in our main package.json file which contains project object which has 2 projects now first our main project with type application and?second is our button project which is having type library.
?6) Before publishing our first package we have to create a build of button library using?
?ng build package_name i.e ng build button command.
?7) You have to log in with your NPM credentials using the npm login command. After entering this command you have to add your username password and register your email id.?Then you will receive an OTP over your mail.
领英推荐
?8) After successful login you have navigated to your library build folder and then publish your package using npm publish.
?How to Use Node package
Simply go on npm.js and search package name simple add dependency in your project using npm install package_name.
?Few things that might be blockers for you.
?The package name must be unique if the package already exists you have to choose another name. Or else you can add your username before the package name in the package.json file of your library. Then you can create a build and instead of the npm publish command you have to add one more parameter like npm publish --access=public
?beacause when you add your username before the package name NPM will consider that package is a private package by default and private packages are paid in NPM.
?How to update the NPM package version.
?Simply update your code. Then update the version in package.json. Login using the npm login command then publish your updated version using the npm publish command
Sample Github code click here
Student at B K Birla Institute of Engineering & Technology, Pilani
1 年hey please check this query on stackoverflow , any guidance or help will be appreciated, Thank you in advance. https://stackoverflow.com/questions/77152634/create-an-npm-package-for-react-native-with-swift-libraries
Sr. Software engineer at IGT Solutions
2 年Most imformative??