Moving the global installation location for Node.js packages to a directory in your home folder on a MacBook can be a good way to avoid having to use sudo for npm installs. This allows you to manage global packages without needing administrative privileges. Here’s a step-by-step guide to achieve this:
Open your terminal and run the following command to create a new directory where your global npm packages will be stored:
mkdir ~/.npm-global