node.js - Load custom modules from root directory with NPM -
probably simple answer i'm lost. if i'm in file several directories below root there way can require ('mylib/module1')
in file , have search 'mylib/module1.js' root rather relative path of i'm using require
statement?
obviously if require('underscore') in
package.json, couldn't find way set reference in
package.json` point right folder, like:
dependencies: { "mylib/module1" : "./mylib/module1.js" }
i did find reference browser
allows map client-side files, i'm looking work on back-end.
one way of doing without needing npm support rename mylib
folder node_modules
. can require('module')
.
the reason works because require
searches recursively directory structure until /
looking folders called node_modules
. simple mechanism allows node have multiple levels of lib directories can overridden @ multiple "local" level necessary. example, can have following directory structure:
/usr /home /diplosaurus /node_modules module1.js <-------- version 1 /code /node_modules module1.js <-------- version 2 /projecta /node_modules module1.js <------- beta version main.js /projetb main.js
all code in home directory use version 1 of module1
code in code
directory use version 2 , projecta
uses beta version.
this means can let npm manage project's node_modules
directory yet maintain manually managed, higher level node_modules
directory personal libraries.
Comments
Post a Comment