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?
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.
The require function will look for files in the following order. NPM Modules. It will look in the node_modules folder. Local Modules.
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.
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')
.
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