npm comes bundled with Node.js. The cleanest install path is to install Node via Homebrew, which gets you npm automatically. There are alternatives — nvm and fnm let you run multiple Node versions side-by-side, mise/asdf are polyglot version managers — but for a beginner, brew install node is the right first step.
Once Node is installed, npm is on your PATH. You can upgrade npm independently of Node (the bundled npm is often a few minor versions behind the latest npm). npm install -g npm@latest upgrades npm itself.
One upgrade gotcha: npm install -g npm@latest can sometimes fail with permission errors on macOS if npm's global prefix is in a system path. The cleanest fix is to set npm's global prefix to a user-owned directory like ~/.npm-global, then add ~/.npm-global/bin to your PATH. Or skip the global install entirely and let Homebrew's Node bundle handle the npm version.