Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Require dependency of another dependency in node modules

I've got a simple node app that has single dependency on another app on github. The dependency installs just fine with npm install, but when I try to require something installed there, it says it's not available. For example, the github app installs Mongoose as a dependency. I thought that this parent app would be able to access that module since it is in a child:

var mongoose = require('mongoose') 

The structure looks something like this:

/app   /node_modules     /github_dependency [parent module]       /node_modules         /mongoose [child module] 

Do I just have to include mongoose as a dependency as well in the parent app or is there a way of getting access to that module by way of the child?

like image 891
typeoneerror Avatar asked Mar 16 '12 11:03

typeoneerror


People also ask

For what require () is used in NodeJS?

In NodeJS, require() is a built-in function to include external modules that exist in separate files. require() statement basically reads a JavaScript file, executes it, and then proceeds to return the export object.

Where does require look for modules?

The require function will look for files in the following order. NPM Modules. It will look in the node_modules folder. Local Modules.

What is devDependencies in package json?

Dev Dependencies: In package. json file, there is an object called as dev Dependencies and it consists of all the packages that are used in the project in its development phase and not in the production or testing environment with its version number.


1 Answers

Do I just have to include mongoose as a dependency as well in the parent app or is there a way of getting access to that module by way of the child?

While it's possible for you to e.g. require('github/node_modules/mongoose'), the standard practice is to install all of your dependencies explicitly (i.e., you should include mongoose as a dependency of your app) and require('mongoose').

like image 83
Linus Thiel Avatar answered Oct 11 '22 00:10

Linus Thiel