Fix Unhandled rejection Error: EACCES: permission denied

I was trying to install gulp on my mac.

But I was getting following errors while running command sudo npm install gulp -g

Unhandled rejection Error: EISDIR: illegal operation on a directory, open '/Users/bhargav/.npm/_cacache/....'

Unhandled rejection Error: EISDIR: illegal operation on a directory, open '/Users/bhargav/.npm/_cacache/....'

npm ERR! cb() never called!

npm ERR! This is an error with npm itself. Please report this error at:
npm ERR!     <https://npm.community>

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/bhargav/.npm/_logs/2019-02-05T14_33_58_146Z-debug.log

After a lot of findings from StackOverflow, I found the following solution for that.

You have to run following two commands and that’s it.

sudo chown -R $USER:$GROUP ~/.npm
sudo chown -R $USER:$GROUP ~/.config