If you initially installed Node.js with Homebrew, run:
brew update
brew upgrade node
npm install -g npm
Or as a one-liner:
brew update && brew upgrade node && npm install -g npm
A convenient way to change versions is to use nvm:
brew install nvm
To install the latest version of Node.js with nvm:
nvm install node
If you installed via a package, then download the latest version from nodejs.org. See Installing Node.js and updating npm.