Its best to avoid having to issue sudo when installing nodejs packages as node should never be run as root (same reasons as HTTPD is not run as root). Always install and run node and npm as yourself. To start over with a fresh install of nodejs and npm (below nodejs git gives you npm) on ubuntu (especially after issuing various sudo commands) :
remove or rename these dirs : (created by npm, typically owned by root if you used sudo)
sudo mv ~yourUnixId/.npm ~yourUnixId/ignore.npm
sudo mv ~yourUnixId/tmp ~yourUnixId/ignore_tmp
sudo mv ~yourUnixId/.npmrc ~yourUnixId/ignore_.npmrc
sudo mv ~yourUnixId/.npm-init.js ~yourUnixId/ignore_.npm-init.js
download source from : http://nodejs.org/download/
cd /path/to/downloaded/src/
./configure --prefix=${HOME}/bin/nodejs
make
make install # will install into above prefix dir
jack up your PATH to find new executables
export PATH=${HOME}/bin/nodejs/bin:$PATH:.
this defines path to reach nodejs modules when issuing npm commands :
export NODE_PATH=${HOME}/bin/nodejs/lib/node_modules
going forward always issue npm install AS YOURSELF NOT sudo with the -g flag as
npm install someCoolModule -g
execute node as yourself :
node myNode.js
you should be all set now - enjoy