How to use NPM Install (The Command) behind Corporate Proxy Server

This article describes a step by step solution to use NPM install command when you are working behind any corporate proxy server.

Problem

When you want to install packages for angular, angular CLI, typescript etc. via NPM using Command Prompt and you are working in an office environment where everything runs behind a corporate proxy server, you will most probably get the below exception,

NPM

Even while working on the Angular project using Visual Studio and trying to restore packages with the help of package.json, developers find the message “Package Restoring Complete” in Visual Studio title bar, but when they look for the node_modules folder inside the project folder, the node_modules folder does not exist. Developers usually find the below exception in output window of visual studio,

  1. === = Executing command 'npm install' === = npm WARN package.json angular - quickstart @1 .0 .0 No README data  
  2. npm http GET https: //registry.npmjs.org/systemjs  
  3.     npm http GET https: //registry.npmjs.org/angular-in-memory-web-api  
  4.     npm http GET https: //registry.npmjs.org/core-js  
  5.     npm http GET https: //registry.npmjs.org/rxjs  
  6.     npm http GET https: //registry.npmjs.org/zone.js  
  7.     npm http GET https: //registry.npmjs.org/concurrently  
  8.     npm http GET https: //registry.npmjs.org/lite-server  
  9.     npm http GET https: //registry.npmjs.org/typescript  
  10.     npm http GET https: //registry.npmjs.org/tslint  
  11.     npm http GET https: //registry.npmjs.org/lodash  
  12.     npm http GET https: //registry.npmjs.org/jasmine-core  
  13.     npm http GET https: //registry.npmjs.org/karma  
  14.     npm http GET https: //registry.npmjs.org/karma-cli  
  15.     npm http GET https: //registry.npmjs.org/karma-chrome-launcher  
  16.     npm http GET https: //registry.npmjs.org/karma-jasmine  
  17.     npm http GET https: //registry.npmjs.org/karma-jasmine-html-reporter  
  18.     npm http GET https: //registry.npmjs.org/protractor  
  19.     npm http GET https: //registry.npmjs.org/canonical-path  
  20.     npm http GET https: //registry.npmjs.org/angular/forms  
  21.     npm http GET https: //registry.npmjs.org/angular/http  
  22.     npm http GET https: //registry.npmjs.org/angular/router  
  23.     npm http GET https: //registry.npmjs.org/angular/platform-browser  
  24.     npm http GET https: //registry.npmjs.org/angular/platform-browser-dynamic  
  25.     npm http GET https: //registry.npmjs.org/angular/core  
  26.     npm http GET https: //registry.npmjs.org/angular/compiler  
  27.     npm http GET https: //registry.npmjs.org/angular/common  
  28.     npm http GET https: //registry.npmjs.org/rimraf  
  29.     npm http GET https: //registry.npmjs.org/types/node  
  30.     npm http GET https: //registry.npmjs.org/types/jasmine  
  31.     npm http GET https: //registry.npmjs.org/rxjs  
  32.     npm http GET https: //registry.npmjs.org/systemjs  
  33.     npm http GET https: //registry.npmjs.org/core-js  
  34.     npm http GET https: //registry.npmjs.org/angular-in-memory-web-api  
  35.     npm http GET https: //registry.npmjs.org/zone.js  
  36.     npm http GET https: //registry.npmjs.org/concurrently  
  37.     npm http GET https: //registry.npmjs.org/lite-server  
  38.     npm http GET https: //registry.npmjs.org/typescript  
  39.     npm http GET https: //registry.npmjs.org/karma-chrome-launcher  
  40.     npm http GET https: //registry.npmjs.org/karma-cli  
  41.     npm http GET https: //registry.npmjs.org/lodash  
  42.     npm http GET https: //registry.npmjs.org/karma-jasmine  
  43.     npm http GET https: //registry.npmjs.org/karma  
  44.     npm http GET https: //registry.npmjs.org/karma-jasmine-html-reporter  
  45.     npm http GET https: //registry.npmjs.org/protractor  
  46.     npm http GET https: //registry.npmjs.org/jasmine-core  
  47.     npm http GET https: //registry.npmjs.org/tslint  
  48.     npm http GET https: //registry.npmjs.org/angular/platform-browser  
  49.     npm http GET https: //registry.npmjs.org/angular/platform-browser-dynamic  
  50.     npm http GET https: //registry.npmjs.org/angular/http  
  51.     npm http GET https: //registry.npmjs.org/angular/compiler  
  52.     npm http GET https: //registry.npmjs.org/types/node  
  53.     npm http GET https: //registry.npmjs.org/angular/forms  
  54.     npm http GET https: //registry.npmjs.org/angular/core  
  55.     npm http GET https: //registry.npmjs.org/rimraf  
  56.     npm http GET https: //registry.npmjs.org/angular/router  
  57.     npm http GET https: //registry.npmjs.org/canonical-path  
  58.     npm http GET https: //registry.npmjs.org/types/jasmine  
  59.     npm http GET https: //registry.npmjs.org/angular/common  
  60.     npm http GET https: //registry.npmjs.org/rxjs  
  61.     npm http GET https: //registry.npmjs.org/systemjs  
  62.     npm http GET https: //registry.npmjs.org/zone.js  
  63.     npm http GET https: //registry.npmjs.org/angular-in-memory-web-api  
  64.     npm http GET https: //registry.npmjs.org/core-js  
  65.     npm http GET https: //registry.npmjs.org/lite-server  
  66.     npm http GET https: //registry.npmjs.org/karma  
  67.     npm http GET https: //registry.npmjs.org/concurrently  
  68.     npm http GET https: //registry.npmjs.org/karma-jasmine  
  69.     npm http GET https: //registry.npmjs.org/karma-chrome-launcher  
  70.     npm http GET https: //registry.npmjs.org/karma-cli  
  71.     npm http GET https: //registry.npmjs.org/typescript  
  72.     npm http GET https: //registry.npmjs.org/lodash  
  73.     npm http GET https: //registry.npmjs.org/jasmine-core  
  74.     npm http GET https: //registry.npmjs.org/karma-jasmine-html-reporter  
  75.     npm http GET https: //registry.npmjs.org/protractor  
  76.     npm http GET https: //registry.npmjs.org/tslint  
  77.     npm http GET https: //registry.npmjs.org/angular/platform-browser  
  78.     npm http GET https: //registry.npmjs.org/angular/platform-browser-dynamic  
  79.     npm http GET https: //registry.npmjs.org/angular/compiler  
  80.     npm http GET https: //registry.npmjs.org/angular/http  
  81.     npm http GET https: //registry.npmjs.org/types/node  
  82.     npm http GET https: //registry.npmjs.org/angular/router  
  83.     npm http GET https: //registry.npmjs.org/angular/core  
  84.     npm http GET https: //registry.npmjs.org/angular/forms  
  85.     npm http GET https: //registry.npmjs.org/canonical-path  
  86.     npm http GET https: //registry.npmjs.org/angular/common  
  87.     npm http GET https: //registry.npmjs.org/rimraf  
  88.     npm http GET https: //registry.npmjs.org/types/jasmine  
  89.     npm ERR!network tunneling socket could not be established, cause = connect ECONNREFUSED  
  90. npm ERR!network This is most likely not a problem with npm itself  
  91. npm ERR!network and is related to network connectivity.  
  92. npm ERR!network In most cases you are behind a proxy or have bad network settings.  
  93. npm ERR!network  
  94. npm ERR!network If you are behind a proxy, please make sure that the  
  95. npm ERR!network 'proxy'  
  96. config is set properly.See: 'npm help config'  
  97. npm ERR!System Windows_NT 6.2 .9200  
  98. npm ERR!command "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\IDE\\Extensions\\Microsoft\\Web Tools\\External\\\\node\\node"  
  99. "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\IDE\\Extensions\\Microsoft\\Web Tools\\External\\npm\\node_modules\\npm\\bin\\npm-cli.js"  
  100. "install"  
  101. npm ERR!cwd D: \Rahul\ PRACTICES\ Angular\ Angular2MVC\ Angular2MVC  
  102. npm ERR!node - v v0 .10 .31  
  103. npm ERR!npm - v 1.4 .9  
  104. npm ERR!code ECONNRESET  
  105. npm === = npm command completed with exit code 1 === =  

Solution

To solve the above problem, you need to follow the below steps,

Step 1

Open command prompt of your system (run as administrator).

Step 2

In command prompt, type the below-highlighted command and enter,

C:\windows\system32>ping proxy                                                                                                                          

Step 3

You will find proxy URL of your work environment very similar to the below proxy URL format in the first line,

proxy.[company name].com     

NPM                                                                               

Note

Due to security purpose, I cannot show you the exact proxy URL of my work environment.

On pressing enter after writing above proxy command, you will get the output very similar to the about command window. You will get the proxy URL of your work environment in the first line.

Step 4

Now you need to set this proxy URL to your NPM config file using the command prompt. Run the below both commands one by one and enter (if the proxy doesn't need credentials),

  1. >npm config set https-proxy http://proxy.[Company Name].com:8080                                                                   
  2. >npm config set https-proxy http://proxy.[Company Name].com:8080        

NPM

In case proxy needs credentials, you need to pass credentials like below,

  1. >npm config set https-proxy http://<username>:<password>@proxy.[Company Name].com:[Port]                                                                            
  2. >npm config set https-proxy http://<username>:<password>@proxy.[Company Name].com:[Port]          

Step 5

Now you will be able to install any npm package just as below I am able to install TypeScript here,

NPM

Step 6

Once TypeScript is installed successfully, run the below command just to check which TypeScript version is installed,

>tsc –v                                                                                                                                                                                  

Note

To read more articles on Angular 2, please check out the below link,

Write me in comment box in case you have any questions or concerns. Have a great day!


Similar Articles