How to configure nodejs npm or python pip package manager to use proxy at work on Windows PC with ntlm authentication (cntlm)?

How to configure nodejs npm or python pip package manager to use proxy at work on Windows PC with ntlm authentication (cntlm)?
 
When you at work - you work under Domain network and your internet access goes through corporate proxy. 
It authenticates you by your credential: Domain, Username and Password each time. But it also can authenticate your using NTLM. 
I will not explain how it is working but it uses token transfer instead of username and password clear text. Most apps like Google Chrome have built in NTLM resolver and work ot of the box.
 
Either npm or pip don't work by default - it needs proxy configuration.
 
For nodejs npm there is global config file under your user folder: 
 
C:\Users\USERNAME\.npmrc
 
with contents for proxy:
 
strict-ssl=false
proxy=http://DOMAIN%5USERNAME:PASSWORD@proxy-srv1.yourcorp.com:8080
https-proxy=http://DOMAIN%5USERNAME:PASSWORD@proxy-srv1.yourcorp.com:8080
 
As you can see you could just hard type your domain, username and password as cleartext, but it is insecure and unuseful each time your password changed retype for each app.
 
For pip similar solution to type proxy settings but config file lays by path:
 
C:\Users\USERNAME\AppData\Local\pip\pip.ini
 
with contents like:
 
[global]
proxy = http://user:password@proxy_dns_or_ip:port
 
Ok, we need a global proxy instance on our local machine. I use cntlm (http://cntlm.sourceforge.net/) - configure it like stackoverflow suggests https://stackoverflow.com/questions/14149422/using-pip-behind-a-proxy
 
cntlm config file asks you to type password in cleartext but it also has solution to store it as hash. To compute hash strings you need in terminal run:
 
cntlm.exe -c "C:\path\to\cntlm\config\cntlm.ini" -H
 
and get outputs:
 
Password:
PassLM          DE198B046B51FA2FB7C56B1A7EBB4049
PassNT          3232B50568AB43AE0BB765328E59A8F4
PassNTLMv2      046A82597F0D706AB6AB3A67D9967F62    # Only for user 'USERNAME', domain 'DOMAIN'
 
Paste that into the config and comment Password line with #
 
Also, type proxy ip:port to yours corp proxy address and save it. We use 3128 port by default.
 
Well, our proxy ready and we need to modify both npm and pip configs to match proxy http://localhost:3128 for both https and http without username and password.
 
Start cntlm proxy process in foreground by command:
 
cntlm.exe -f -c "C:\path\to\cntlm\config\cntlm.ini"
 
and now you can run npm or pip install commands and it will work through cntlm proxy.

cntlm, nodejs, npm, python, pip, proxy, windows, ntlm