Is there any way to develop and test the reusable packages at the same time without re-installing…
By Vinoth S — “An Enthusiast Coder thrives for learning”
As a developer, I used to think of a way to test the reusable component in my main application before publishing the changes to the remote server.
By default, I will complete the coding for project library “B” and push it to the remote server and then I will use project “B” in the dependencies of Project “A”.
And then the npm install helps here..Finally !! Here comes the real-time testing phase
Are we need such a long process? The wait is over by using the “npm Link” command.
2. npm unlink– Once you’re done with real-time testing, then you can break the symlink by using the npm unlink command.
For example, I have 20+ microservices in the global project where we have repeated code related to HTTP calls, Messaging queues implementation, caching, database / elastic search/ AWS connection, etc in each microservices.
To optimize this, we will create a “reusable-lib”, move the set of repeated codes to a separate repository and publish it as a separate module. Let’s create one shared library named “reusable-lib” which contains the different basic functionalities required for our main application and the same can be used across different microservices in our project.
Now let’s start with real-time implementation where we have one main project named “core-app” and one shared project “reusable-lib”.
After creating the npm link for “reusable lib”, now we can use the same in other projects.
Now the symlink has been established between “reusable-lib” and “core-app”.
We can create a new file “index.js” in the “reusable-lib” and without using the npm install command in “core-app”, the same will be available within the “node_modules” folder of our “core-app”.
Now the index.js file within the “reusable-lib” and “core-app” will have a symlink and the changes will reflect in real-time.
Once we have done with our real-time testing, then it’s time to remove the symlink from “reusable-lib” using the npm unlink command. Then, “reusable-lib” will be no longer accessed in real-time from other projects.
Hope this information helps !! It will reduce some of our developer’s time in the testing phase.
Thank you for reading the article!! I appreciate your feedback :)
We at CaratLane are solving some of the most intriguing challenges to make our mark in the relatively uncharted omnichannel jewellery industry. If you are interested in tackling such obstacles, feel free to drop your updated resume/CV to email@example.com