I am trying to setup Node on Mac OSX Lion. It all seems to work ok, but I can't seem to import anything modules from my global modules folder. I get the error,
Error: Cannot find module <module>
If I run this: node -e require.paths
, the response I get is:
[ '/usr/local/lib/node_modules',
'/Users/Me/.node_modules',
'/Users/Me/.node_libraries',
'/usr/local/Cellar/node/0.4.12/lib/node' ]
Which is correct, my modules are indeed installed in /usr/local/lib/node_modules. When I try and run a script, however, I am getting this:
Error: Cannot find module 'socket.io'
at Function._resolveFilename (module.js:326:11)
at Function._load (module.js:271:25)
at require (module.js:355:19)
at Object.<anonymous> (/Users/Me/node/server.js:2:10)
at Module._compile (module.js:411:26)
at Object..js (module.js:417:10)
at Module.load (module.js:343:31)
at Function._load (module.js:302:12)
at Array.<anonymous> (module.js:430:10)
at EventEmitter._tickCallback (node.js:126:26)
My .bash_profile looks like this:
export PATH=/usr/local/mysql/bin:$PATH
export NODE_PATH=/usr/local/lib/node_modules
export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:/usr/local/mysql/lib/"
Would really appreciate some help, I have no idea why I can't import any libraries.
Install any package globally as below:
As this replace module is installed globally so if you see your node modules folder you would not see replace module there and so you can not use this package using require('replace').
because with require you can use only local modules which are present in your node module folder.
Now to use global module you should link it with node module path using below command.
Now go back and see your node module folder you could now be able to see replace module there and can use it with require('replace') in your application as it is linked with your local node module.
Pls let me know if any further clarification is needed.
You can use require with the path to the global module directory as an argument.
On my mac, I use this:
How to find where your global modules are? --> Where does npm install packages?