Access google translation API through proxy using nodejs

Written by inevity

Client network socket disconnected before secure TLS connection was established

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.