How to fix Node.js npm permission problems

With node version 0.6.10 and npm version 1.1.0-3, you may run into this error when installing a module on Windows, not just the Azure module:

 PS> npm install azure
npm http GET https://registry.npmjs.org/azure
npm http 200 https://registry.npmjs.org/azure
npm http GET https://registry.npmjs.org/azure/-/azure-0.5.2.tgz
npm http 200 https://registry.npmjs.org/azure/-/azure-0.5.2.tgz
npm ERR! Could not unpack C:\Users\Matt\AppData\
  Roaming\npm-cache\azure\0.5.2\package.tgz 
  to C:\Users\Matt\AppData\Roaming\npm-cache\azure\0.5.2

npm ERR! Error: EPERM, operation not permitted 
  'C:\Users\Matt\AppData\Roaming\npm-cache\
  azure\0.5.2\___package.npm\package'
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR!
npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\\Program Files (x86)\\nodejs\\\\node.exe" 
  "C:\\Program Files (x86)\\nodejs\\node_modules\\npm\\bin\\
  npm-cli.js" "install" "azure"
npm ERR! cwd C:\Users\Matt\Documents\src\node
npm ERR! node -v v0.6.10
npm ERR! npm -v 1.1.0-3
npm ERR! path C:\Users\Matt\AppData\Roaming\npm-cache\
  azure\0.5.2\___package.npm\package
npm ERR! code EPERM
npm ERR! message EPERM, operation not permitted 
  'C:\Users\Matt\AppData\Roaming\npm-cache\
  azure\0.5.2\___package.npm\package'
npm ERR! errno {}
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     C:\Users\Matt\Documents\src\node\npm-debug.log
npm not ok

It turns out that you don’t have to run the command again as Administrator, and doing so won’t fix the problem.  Try npm cache clean first.  If that doesn’t fix things, take a look in %APPDATA%\npm-cache, or if you’re using PowerShell, $env:APPDATA\npm-cache.  After cleaning the cache, you may still be left with remnants.  Manually remove everything in that directory, and try again.  This has always fixed things for me.