Last Updated: July 12, 2019
·
15.35K
· jamischarles

Use 'npm link' to edit an Node.js npm module locally

Use case:

Say you are running a node app, and you think the NPM module you're using is causing a bug. What's the easiest way to dive in and edit the module? Here's how...

We'll assume that the module with the bug is Express.

The steps

  1. Navigate to the npm module folder (app_name/node_modules/express/).

  2. Then create a global symlink to that npm module.

    npm link
  3. Navigate back to your project folder (app_name)

  4. In your project folder, now reference that symlink.

    npm link express

Next

Now every time you edit anything in appname/nodemodules/express, you just need to refresh to see the effects in your app. No need to rebuild, or npm anything.

When you've verified it works, you can check it in to github or whatnot. This makes testing locally nice and painless.

Sources:
https://npmjs.org/doc/link.html

1 Response
Add your response

Does not work: "Link target resolves to the same directory as link source"

over 1 year ago ·