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?
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_modulessub-directory by default.