Reputation: 31652
I'm new to node.js - so I think my question is best asked with an example:
The Connect
framework requires the mime
module - and loads is as such: require('mime')
If I wanted to make this a local module (i.e. I've placed the mime
module within my project instead of installing it into node.js's Core Modules folder) is there some way for me to associate that module name with my known path to that module?
Upvotes: 0
Views: 904
Reputation: 3101
You can reference a module three ways:
mime = require('./lib/mime.js');
mime = require('/home/usr/www/lib/mime.js');
mime = require('mime');
For the search method, Node starts in your app's directory, and adds ./node_modules/
and tries to load from that location. If that fails it moves to the parent directory and so on until it hits the root.
If you're in your app's directory and install a module (like mime) via NPM, it'll install it in that node_modules
sub-directory by default.
Upvotes: 2