npm install
now supports thisnpm install --save ../path/to/mymodule
For this to work mymodule
must be configured as a module with its own package.json
. See Creating NodeJS modules.
As of npm 2.0, local dependencies are supported natively. See danilopopeye's answer to a similar question. I've copied his response here as this question ranks very high in web search results.
This feature was implemented in the version 2.0.0 of npm. For example:
{ "name": "baz", "dependencies": { "bar": "file:../foo/bar" } }
Any of the following paths are also valid:
../foo/bar ~/foo/bar ./foo/bar /foo/bar
Since npm install
copies mymodule
into node_modules
, changes in mymodule
's source will not automatically be seen by the dependent project.
There are two ways to update the dependent project with
Update the version of mymodule
and then use npm update
: As you can see above, the package.json
"dependencies" entry does not include a version specifier as you would see for normal dependencies. Instead, for local dependencies, npm update
just tries to make sure the latest version is installed, as determined by mymodule
's package.json
. See chriskelly's answer to this specific problem.
Reinstall using npm install
. This will install whatever is at mymodule
's source path, even if it is older, or has an alternate branch checked out, whatever.