Access google translation API through proxy using nodejs


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


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');

  host: '',
  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.



When you post a tweet with a link to this post it will automatically show up here! (refreshed every 30 minutes) 💯

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.

More from 格物治用


View all posts