Make Friends with Your Current Dev Node Modules and Bower Components

Posted by Chris Britz

Jul 29, 2014 5:01:00 PM Node js

In this post I will talk about npm link, however, if you just replace npm with bower you will be able to perform the same feature. There is one difference to note though. To have bower link work you must be in the directory where the bower.json file resides instead of the package.json file. Most of the time they reside in the same location, but sometimes they do not.

NPM/Bower link is a great feature from npm/bower that allows you to instead of copying and pasted code changes in one project to another via IDE, or performing a git push to one project and then doing an npm install in the other in order to get the latest changes, you can create a globally-installed symbolic link that enables the local changes from your dev module and includes it in your application that requires it. This allows you to make changes one place and they in effect in real time in the other, so there is no need to do worry about copying and pasting code from a project dependent upon a npm package

Now npm link is super easy to use. Basically, you can get this great feature by just performing these easy steps.

  1. cd into the forked/cloned repo directory (where package.json exists) of the npm dependency you want to link to your main project. For example, if project A depends on project B then cd into where project B resides.
  2. Perform npm link command. This command will use the name: field in your package.json file as the name for the symbolic link.
  3. cd into the project that is dependent upon your linking project. For example, if project A depends on project B then cd into project A where the package.json file resides.
  4. Perform npm link projectB where projectB is your project name that you performed the first npm link on.

And thats it!! Now your projects are linked together for development on both projects at the same time. Now that's being productive. One thing I would like to mention is that when you delete your node_modules directory this will remove the symbolic link, so you will have to perform step 3 and 4 again to reestablish the global link again.

Subscribe to the Vizuri Blog

Posted by Chris Britz

Avid software developer for Vizuri, Runner, Jeeper, Mountain Biker, and anything above. I am a person who loves to learn and learns to love.

    
Request a Complimentary Docker Consultation

An Open View

Vizuri Blog

Subscribing to our blog is a great way to stay up to date with the latest information from Vizuri, as well as our strategic partners. We focus on providing a range of content that is practically useful and relevant from both a technical and business perspective.

We promise to respect your privacy.

×