diff options
author | isaacs <i@izs.me> | 2010-10-13 17:15:56 -0700 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2010-10-20 15:45:47 -0700 |
commit | b0adaff67e492ab9ac583059f5e2dba54de0973b (patch) | |
tree | eaff2defc2c565b09972b4fe5a255bb8a74f4a30 /doc | |
parent | bfc6b51d955089a7e5b23807b4722cdaec0a8e0b (diff) | |
download | nodejs-b0adaff67e492ab9ac583059f5e2dba54de0973b.tar.gz nodejs-b0adaff67e492ab9ac583059f5e2dba54de0973b.tar.bz2 nodejs-b0adaff67e492ab9ac583059f5e2dba54de0973b.zip |
require looks in node_modules folders
for modules starting with the __dirname and moving up.
This makes it much easier to localize dependencies to a particular program.
Diffstat (limited to 'doc')
-rw-r--r-- | doc/api.markdown | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/doc/api.markdown b/doc/api.markdown index 3dc1e63e8..9f8d76546 100644 --- a/doc/api.markdown +++ b/doc/api.markdown @@ -446,13 +446,12 @@ but rather than loading the module, just return the resolved filename. ### require.paths -An array of search paths for `require()`. This array can be modified to add custom paths. +An array of search paths for `require()`. This array can be modified to add +custom paths. Example: add a new path to the beginning of the search list require.paths.unshift('/usr/local/node'); - console.log(require.paths); - // /usr/local/node,/Users/mjr/.node_libraries ### __filename @@ -3259,6 +3258,15 @@ a directory. `require.paths` can be modified at runtime by simply unshifting new paths onto it, or at startup with the `NODE_PATH` environmental variable (which should be a list of paths, colon separated). +Additionally node will search for directories called `node_modules` starting +at the current directory (of the module calling `require`) and upwards +towards the root of the package tree. +This feature makes it easy to have different module versions for different +environments. Imagine the situation where you have a devopment environment +and a production environment each with a different version of the `foo` +module: `projects/x/development/node_modules/foo` and +`projects/x/production/node_modules/foo`. + The second time `require('foo')` is called, it is not loaded again from disk. It looks in the `require.cache` object to see if it has been loaded |