I have an application which has the usual set of dependencies on third party modules (e.g. 'express') specified in the package.json file under dependencies. E.g.
"express" : "3.1.1"
I would like to structure my own code modularly and have a set of local (meaning on the file system i am currently in) modules be installed by the package.json. I know that i can install a local module by running:
npm install path/to/mymodule
However, I don't know how to make this happen via the package.json dependencies structure. Using the --save
option in this command is simply putting "mymodule": "0.0.0"
into my package.json (doesn't reference the filepath location). If i then remove the installed version from node_modules, and try to re-install from the package.json, it fails (because it looks for "mymodule" in the central registry, and doesn't look locally).
I'm sure the is a way of telling the "dependencies": {}
structure that I want it to be installed from a file system path, but don't know how.
Anyone else had this problem? Thanks.
If it's acceptible to simply publish your modules preinstalled in node_modules alongside your other files, you can do it like this:
You may also want to store your module on git and tell your parent package.json to install the dependency from git: https://npmjs.org/doc/json.html#Git-URLs-as-Dependencies
As of NPM 2.0.0, importing local dependencies is supported natively. This was documented by danilopopeye in response to a similar question. I've copied his response here to help anyone needing to find the correct answer, as this question ranks very highly in Google's search results.
See: Local dependency in package.json
It looks like the answer is
npm link
: https://docs.npmjs.com/cli/linkI couldn't find a neat way in the end so I went for create a directory called
local_modules
and then added this bashscript to the package.json in scripts->preinstallAfter struggling much with the
npm link
command (suggested solution for developing local modules without publishing them to a registry or maintaining a separate copy in the node_modules folder), I built a small npm module to help with this issue.The fix requires two easy steps.
First:
Second, add this to your
package.json
:More details at https://www.npmjs.com/package/lib-manager. Hope it helps someone.