To fix Permission denied when installing npm modules in OSX, we change the permission of the node_modules directory.
For instance, we run
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
to run chown
to get the user with whoami
and then set the node_modules, bin, and share directories’ owner to the current user.
And then we install packages with
sudo npm install