When trying to install grunt to compile Bootstrap JS and CSS I found this error:

npm ERR! Error: EACCES: permission denied, access ‘/usr/local/lib’

After providing sudo then this error appeared:

npm ERR! network request to https://registry.npmjs.org/grunt-cli failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org registry.npmjs.org:443

Well, if you are executing sudo to install you should export the proxy settings for the elevated user as well, so run this commands as explained here with sudo:

And it will work: