I tried following options to fix this issue and it worked.
For example to install express I used following command.
npm install express --registry http://registry.npmjs.org/
or
npm install express -g --registry http://registry.npmjs.org/
If you want to install locally in any specific folder then use below command. Below command will install express on path C:\Sample\Example1
.
C:\Sample1\Example1> npm install /Sample/Example1 express --registry http://registry.npmjs.org/
Note: If you are installing locally in a specific location then first go to that directory using command and then run above command. If you are not inside that directory and giving only path in command that will not work.
If you get package.json
missing error then run below command before installing package locally
C:\Sample\Example1> npm init
above command will create package.json
file. No need to provide any data. just hit enter.
Note: If you are behind a firewall then you may need to set a proxy.