At an absolute minimum, you need to go into the home directories (the ones that start with ~/) and make sure you are okay with deleting the contents of those directories. If you are unsure if this will delete anything important, you should stop now and find another alternative for re-installing Node.js, because this approach is pretty destructive.
rm -rf ~/local
rm -rf ~/lib
rm -rf ~/include
rm -rf ~/node*
rm -rf ~/npm
rm -rf ~/.npm*
sudo rm -rf /usr/local/lib/node*
sudo rm -rf /usr/local/include/node*
sudo rm -rf /usr/local/bin/node
sudo rm -rf /usr/local/bin/npm
sudo rm -rf /usr/local/share/man/man1/node.1
sudo rm -rf /usr/local/lib/dtrace/node.d
Or better:
First part to delete - https://gist.github.com/DanHerbert/9520689
rm -rf /usr/local/lib/node_modules
brew uninstall node
then to install - https://gist.github.com/DanHerbert/9520689#gistcomment-2129349
brew install node
npm install npm --global
brew install node
gives:
Downloading https://nodejs.org/dist/v8.4.0/node-v8.4.0.tar.xz
==> ./configure --prefix=/usr/local/Cellar/node/8.4.0 --without-npm --with-intl=system-icu
==> make install
==> Downloading https://registry.npmjs.org/npm/-/npm-5.3.0.tgz
==> node /private/tmp/node-20170820-29397-1gm0jc8/node-v8.4.0/npm_bootstrap/bin/npm-cli.js install -ddd --global --prefix=/usr/local/Cellar/node/8.4.0/libexec /Users/user/Library/Caches/Homebrew/node--npm
==> Caveats
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
==> Summary
/usr/local/Cellar/node/8.4.0: 4,152 files, 47.3MB, built in 15 minutes 55 seconds