Access google translation API through proxy using nodejs
Issue
When use env var proxy such as http or https_proxy to run node xx.js, node console will emit the error
Error: Client network socket disconnected before secure TLS connection was established
Solution
We can switch to use another way which is to set proxy in the code.
Put the code below to the front of code.
var globalTunnel = require('global-tunnel-ng');
globalTunnel.initialize({
host: '192.168.1.1',
port: 8123,
sockets: 50 // optional pool size for each http and https
});
The conditon is that any module that doesn't specify an explicit agent: option to http.request will also work with global-tunnel.
A small favor
Was anything I wrote confusing, outdated, or incorrect? Please let me know! Just write a few words below and I'll be sure to amend this post with your suggestions.
Follow along
If you want to know about new posts, add your email below. Alternatively, you can subscribe with RSS.