Frontend Mayhem

Npm link : What is it & when to use it?

July 16, 2018

Writing your own node modules & sharing them with the community is a lot of fun! However, things can get a bit difficult when you’re developing an npm module & a project that depends on it.

You want to test a new version of your module against your project without having to publish it over & over again. Also, if your module is popular in the community then it’s downright impractical to just publish new versions in that scenario.

I personally felt this pain when developing my own ESLint plugins. Despite having a lot of tests I wanted to see the updated rules in action in my project before publishing the changes.

This is where npm link comes into play!

Using npm link

  1. Navigate to the directory where the development version your module resides & npm link. This will create a symlink in the global node_modules folder.

  2. Navigate to the directory where your project resides & run npm link <package name>. The package name is taken from package.json. This will create a symlink from the globally installed package to this folder’s node_modules.

Now you can just require your module in the project & it will use the globally installed development version of your module.


Watandeep Sekhon

Written by Watandeep Sekhon.
Website / Twitter / LinkedIn / Instagram