It sounds like there are several problems.
right now whenever I install something with npm -g, it installs it in my OSX home folder (!!) and it is not accessible globally.
npm maintains a cache in ~/.npm in your home directory. This is not an installation location, just a cache of downloaded packages and other data. If this is causing you grief, you can get rid of it temporarily with
npm cache clean
npm
will recreate and repopulate the cache as it runs.
One way to rescue the situation is to download and run this script < https://github.com/DomT4/scripts/blob/master/OSX_Node_Removal/terminatenode.sh > which will remove node completely. You can then install with the installer < http://nodejs.org/download/ > or homebrew, whichever you prefer.
One last point, though, is that when you install a package globally, you cannot require
it: you get new commands. For example:
$ jshint
-bash: jshint: command not found
$ npm install -g jshint
$ jshint
$
Now I have the jshint
command installed and can use it to analyze source files; but I cannot require('jshint')
from any code, because that doesn't look in the global node_modules
directory. This is intentional; the goal is to make each package declare its dependencies completely, so it is easier to move a package from one host to another without having to figure out what undocumented dependencies need to be installed on the target system.