The obvious way to promote a bundled dependency to a global module is by moving the directory from node_modules/foo/node_modules/baz
to node_modules/baz
but is that all I have to do? Is there a secret handshake, without which things will mysteriously go wrong?
(While I'm asking yes/no questions: I notice that npm drops the node_module under whatever directory I happen to be in at the moment. Is this intended behavior -- I can see how it would be useful for recursive installation of dependencies -- or did I, with no sense of irony, mess up the installation of npm?)
(And speaking of yes/no questions about messed-up installations, my install of node does not automatically look in its own node_modules directory, I had to add it to NODE_PATH. Is this expected behavior?)
My appraisal after two days of node.js: great product, I d开发者_开发百科on't see why it isn't even more popular than it is -- I'm most the way through solving a problem that is absolutely unsolvable in the standard Apache/Tomcat systems I'm used to -- but it's harder to find answers to really simply question, like the above, than the big-picture ones ("how do I connect to MySQL?" "how do I load-balance?")
npm as of version 1.0 changed how it did it's installations in terms of Global vs Local.
The short answer is if you want to install a module globally you can use the -g
flag.
npm install awesome-module -g
If you want it locally you drop the -g
flag.
If you want your module to only be installed globally you can add
"preferGlobal": true
to your package.json
As far as your second question goes, yes it is the intended behavior to drop node_module
in whatever directory you're in, that's part of the local installation.
Link to npm 1.0 release blog: http://blog.nodejs.org/2011/03/23/npm-1-0-global-vs-local-installation/
精彩评论