Connor
Connor

Reputation: 4168

Use local version of node.js package

I'm digging into a node package that uses a CLI, and am trying to extend it by adding some functionality. I've cloned the repo from github, but I've also installed it via npm.

How can I use my local version, instead of the one that's been installed via npm?

Thanks!

Upvotes: 1

Views: 740

Answers (1)

Dobes Vandermeer
Dobes Vandermeer

Reputation: 8820

When you install a package using npm, it just puts it into the node_modules folder in the folder where you ran it (or if you pass -g, into a global node_modules folder).

require() uses a particular search order to find modules. To get a specific version of a module to load you can take two paths:

  1. Specify a relative path to the module: require("./path/to/myfork/of/module")
  2. Delete the version of the module installed by npm into mode_modules and put your fork of it in there
  3. Make sure that your fork of that module is in a "closer" node_modules folder. Node searches the node_modules in same folder as the file calling require() and then works its way up the folder hierarchy to find a module.

For more information, take a look at http://nodejs.org/docs/v0.4.11/api/modules.html

Upvotes: 2

Related Questions