How to create NodeJS custom libraries
Hello 👋🏼,
My name is Andrei, I am a Senior NodeJS Developer & #AWS Architect Consultant / Contractor / Freelancer. 👨🏻💻
This post will guide you on creating #NodeJS custom libraries for your projects. 😊___________________
Prerequisites:
___________________
What is NodeJS? What is npm? 👀
Node.js is a free, open-sourced, cross-platform JavaScript run-time environment that lets developers write command line tools and server-side scripts outside of a browser. 🚀 (ref: https://nodejs.dev/ )
#npm is installed with Node.js, it is the largest software registry. The name npm (Node Package Manager) stems from when npm was first created as a package manager for Node.js. (ref: https://www.w3schools.com/whatis/whatis_npm.asp)
___________________
Resources
___________________
Hello World Application 💻
Okay, so first things first 📌
npm init
The application code is simple - the sum of two numbers received as input arguments.
Application Run
Recommended by LinkedIn
___________________
Library's content 📚
Inside the #library, you can add code that can be used in multiple nodeJS projects (multiple #lambdas on AWS). 🚀🚀🚀
For the library repository, we will do the npm init again.
As of now, the sample library includes the sum function and a new logger (winston 😎) as an external library, in fact, it is present inside the package.json
In order to create a version of the library, you can create a release 🎁
Once the code is pushed on #GitHub we can update the #package.json of the hello world application in order to use the library functions. 💪
If you want to use the code from a feature branch, you need to replace the tag (v1.0.0) with the branch name (feature/implement-library). 😌
Now, let’s run npm i and update the code with our custom library.
Now if we run the application again, we will use the methods defined inside the library. 🥳
______________________
If you need any help or considerations, feel free to drop me a message 📩