If you run the following command to install npm package:
npm install <package_name>
and get an access error, you might be tempted to run this command with sudo and it'll work, but it's not a right way for sure. Npm modules should be installed without sudo. To fix the problem you need to do two things:
1) Set yourself as an owner of ~/.npm directory, like this:
sudo chown -R $(whoami) ~/.npm
and if error persists, set yourself as an owner /usr/local/lib/node_modules directory too, like this:
sudo chown -R $(whoami) /usr/local/lib/node_modules
Now you can install npm packages without sudo.
Hey, if you've found this useful, please share the post to help other folks find it: