DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Using npm Link to Develop Dependent Projects

Need to keep two related/dependent projects in sync with their respective changes? Check out how to use npm's link feature to make your life easier!

Lorna Mitchell user avatar by
Lorna Mitchell
·
Jan. 13, 17 · Tutorial
Like (1)
Save
Tweet
Share
7.02K Views

Join the DZone community and get the full member experience.

Join For Free

Right now, I'm working on a JavaScript project that relies on another module for some of its functionality. I'm making fairly major changes that affect both projects, and since the dependency is pulled in via npm, initially I was committing and pushing to a repo so that npm could pull in the dependency from GitHub - on every update. Well, that gets tedious really quickly so I'm now using the npm link command which is pretty handy. I hadn't seen it before so this blog post is basically the cheat sheet I wrote when I started using it...

The npm link command essentially creates a symlink in the node_modules folder so that any edits you make in one module will immediately be reflected in any project that has been set up to depend on that (local) version of the module.

Create the Dependency to Link to

The first step is to ask npm to make the dependency available via this mechanism. In my case, I'm using a module called bluemix-helper-config which is a tool for running applications both locally and on Bluemix without making a lot of config changes - very useful! However, I needed to amend it a bit while I was using it, so I exposed it as a link by running npm link from the directory of this dependency.

Npm shows where it has linked to - basically, it becomes a globally available module.

Use the Linked Version of the Module

In my main project (I was setting up a simple-data-pipe to bring in StackOverflow data), I can then link to this module by doing:

npm link bluemix-helper-config


Npm gives some output showing the actual directory it's linked to, the global location, and where that is in my local node_modules folder. You can also see the effect of an npm link setup by listing the contents of the directory - an ls -la command shows where the link goes to.

Beyond the Development Platform

The link is only used locally; if you're pushing to the cloud, you'll still need to publish your dependencies to somewhere that they can be loaded from, even if you set up your package.json to track a branch by doing something like:

    "bluemix-helper-config": "git://github.com/lornajane/bluemix-helper-config.git#remove-vcap-app-host",


I found that this approach improves my development workflow a bit when I find that dependencies need some updates as well as whatever I'm doing — and that using the branch notation means I can ship with my fixes immediately, then update back to a proper version number once a new release is available. If there's something you'd add here, I'd love to hear it - I'm relatively new to Node.js so there's probably some other tips I haven't learned yet!

Npm (software) Links

Published at DZone with permission of Lorna Mitchell, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Beginners’ Guide to Run a Linux Server Securely
  • GPT-3 Playground: The AI That Can Write for You
  • The Data Leakage Nightmare in AI
  • Securing VMs, Hosts, Kubernetes, and Cloud Services

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: