I want to do something like this, so npm install
also installs the package.json
of ../somelocallib
or more importantly its dependencies.
"dependencies": { "express": "*", "../somelocallib": "*" }
The dependencies value is used to specify any other modules that a given module (represented by the package. json ) requires to work. When you run npm install from the root folder of a given module, it will install any modules listed in that dependencies object.
npm install supports local directories and packagesjson 's dependencies. The local package definition will then include the file: prefix. Additionally, it'll create a symlink in your node_modules directory pointing to the local package. That saves a lot of work and is quickly done!
To add dependencies and devDependencies to a package. json file from the command line, you can install them in the root directory of your package using the --save-prod flag for dependencies (the default behavior of npm install ) or the --save-dev flag for devDependencies.
By default, npm install will install all modules listed as dependencies in package. json . With the --production flag (or when the NODE_ENV environment variable is set to production ), npm will not install modules listed in devDependencies .
This feature was implemented in the version 2.0.0 of npm. Local paths can be saved using npm install -S
or npm install --save
, using any of these forms:
../foo/bar ~/foo/bar ./foo/bar /foo/bar
Example package.json
:
{ "name": "baz", "dependencies": { "bar": "file:../foo/bar" } }
npm ls
:
[email protected] /private/tmp/app └── [email protected] -> /private/tmp/somelocallib
Put somelocallib
as dependency in your package.json
as normal:
"dependencies": { "somelocallib": "0.0.x" }
Then run npm link ../somelocallib
and npm will install the version you're working on as a symlink.
Reference: link(1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With