Benchmark.js module cannot find globally in Nodejs


If I install Benchmark.js locally with npm install benchmark than everything works good:

require("benchmark") > Object

But when I try to install Benchmark globally with -g flag npm install benchmark -g, Nodejs cannot find the module (remove first the locally installed benchmark):

require("benchmark") > Error: Cannot find module 'benchmark'

I tryed under Windows and Linux both. The same results. Locally work, globally not. Can anyone help me WHY?

The mongodb module works globally.

Problem courtesy of: Gergely Fehérvári


You can do it using npm link. For example - express - npm link express

npm install -g express
cd <your-application-development-path>
npm link express

A symbolic will be created linking express

xxx@xxx:~/Programming/web/foo$ ls -lrt node_modules
total 12
drwxr-xr-x 2 xxxx xxxx 4096 2011-12-21 17:07 .bin/
lrwxrwxrwx 1 xxxx xxxx 38 2011-12-21 17:07 express -> ../../../node/lib/node_modules/express/

Solution courtesy of: First Zero

View additional discussion.