A quick guide to npm link

JW
1 min readJul 9, 2020

--

What is it?
To setup a local codebase as a package (npm link) that can be used as a dependency in another local codebase npm link {name-of-dependency}.

How to use it?

  1. Inside of the codebase (“Codebase #1”) you want as a dependency package, input into the terminal: npm link.
  2. Inside of the codebase (“Codebase #2”) where you want to consume the dependency, input into the terminal: npm link {name-of-dependency*}
  3. Before you can use Codebase #1 you must run npm pack in the terminal of Codebase #1 to pack up the changes you have made. If you have any custom npm build scripts, you will need to run this before this step, otherwise the standard npm build will be run as part of npm link.
  4. When Codebase #2 is using any of the code in Codebase #1, take care NOT to use the source code (eg. /src) but the built and packaged code.

*Note: the name of the dependency is taken from the package.json of the dependency package.

--

--

JW
JW

Written by JW

Front-End Software Engineer, and avid learner of history.

No responses yet