Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Local dependency in package.json

Tags:

node.js

npm

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": "*" } 
like image 238
user1680104 Avatar asked Jan 17 '13 15:01

user1680104


People also ask

What is dependency in package json?

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.

What is local installation of dependencies in npm?

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!

How do I add a dependency to a package?

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.

Does package json install dependencies?

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 .


1 Answers

npm >= 2.0.0

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 

npm < 2.0.0

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)

like image 112
danilopopeye Avatar answered Sep 20 '22 23:09

danilopopeye