Say you’re developing two Node projects locally, where one (“the project”) depends on the other (“the module”). An example could be a components library and the client-facing UI of your platform.
With every change you’ll make in your components library you’ll need to publish it (
then update your Frontend project (
I know, you’re probably using some sort of a continuous deployment mechanism that builds and packs the module for you. But even then you still need to update the project with the module’s current release version.
That’s too frustrating IMO…
Today Oleg thought me how the magic of npm link saves the day!
We’ll go straight to the example, explanation to follow.
npm linkin the module’s folder:
$ cd ~/workspace/my-module $ npm link
- Run npm link
in the project’s folder:
$ cd ../my-project $ npm link my-module
Removing the symbolic links to undo is super easy thanks to
npm unlink built-in command.
npm unlink --no-save <module_name>in the project’s directory - removes the local symlink.
npm unlinkin the module’s directory - removes the global symlink
npm link in a module’s root directory creates a symbolic link from your global node_modules directory to the local module’s directory.
npm link <module_name> in the project’s directory creates a symbolic link from ./node_modules/
As a result any change you make in your required module will be immediately reflected in your project!
You can actually do the same in one step:
$ cd ~/workspace/my-project $ npm link ../my-module