Sometimes you need to use a module before you are ready to publish a new version of it or you are working around different files of different repositories that are dependent on each other to see the actual change made. To serve this purpose, npm provides us with a command called npm link

This can be better explained by giving examples of npm link usage among different repositories

npm link

Example of npm link

Let’s suppose we have a repository named brands that contains all the less/css files for styling. And there is another repository named eProducts which is using all styling from brands to be used on its website. Now to link between brands and eProducts we will follow the following steps:

  • Type npm link on brands (This can be done on any branch )
  • Go to the eProducts repository and type npm link ../brands.
  • Now you can do npm start on eProducts and check changes (you can also check changes coming in node-modules)

Note – Make sure your npm is installed before. If you face some error it might help remove and re-installing node-modules

Note – Make sure that the repositories path should be given correctly i.e if the repository is in a different directory then you should give the path accordingly. In the given examples, the repositories are in the same directory

Note: – Repositories will only need to be linked together if one is a dependency in the package.json. E.g; in the case of accessing a standalone API, the npm link will not work.

To learn how to configure the packages.json file please look at the blog post Configure package.json file

You can learn about npm commands by exploring the blog post npm command cheat sheet

Categorized in: