Avoid sudo if you can

I ran npm update on a project today, which returned this error:

npm error code EACCES
npm error syscall open
npm error path /Users/-username-/.npm/_cacache/index-v5/ab/83/-long-hash-
npm error errno EACCES
npm error
npm error Your cache folder contains root-owned files, due to a bug in
npm error previous versions of npm which has since been addressed.
npm error
npm error To permanently fix this problem, please run:
npm error   sudo chown -R 501:20 "/Users/-username-/.npm"
npm error A complete log of this run can be found in: /Users/-username-/.npm/_logs/2024-12-11T10_37_38_225Z-debug-0.log

I avoid running sudo commands, especially when it’s node or npm suggesting this.

My solution: 

rm  -r /Users/-username-/.npm

And running npm update again.

Always think twice before running a root command, especially when it’s coming from an online tool.