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,
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,
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
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),
- >npm config set https-proxy http:
- >npm config set https-proxy http:
In case proxy needs credentials, you need to pass credentials like below,
- >npm config set https-proxy http:
- >npm config set https-proxy http:
Step 5
Now you will be able to install any npm package just as below I am able to install TypeScript here,
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!