Node.js is a JavaScript runtime environment that is used by programmers for creating scalable network applications. It is basically a backend JavaScript environment widely used for creating applications simply. When working with node.js, you may experience the error warning “client network socket disconnected before secure tls connection was established”. Check out how the error pops up.
How do you get the error?
When you try to send Google API a request like https://www.googleapis.com/blogger/v3/blogs/2399953?key=…
You end up with the error warning:
Client network socket disconnected before secure TLS connection was established
The code you tried results in the error message:
const {google} = require('googleapis');
const blogger = google.blogger({
version: 'v3',
auth: 'YOUR API KEY'
});
blogger.blogs.get({blogId: '3213900'}, (err, res) => {
if (err) {
console.error(err);
throw err;
}
console.log(`The blog url is ${res.data.url}`);
});
//But I can get result in browser https://blogger.googleapis.com/v3/blogs/3213900?key=xxx
Variation in code you tried:
var request = require("request");
request(
{
url:
"https://blogger.googleapis.com/v3/blogs/3213900?key=xxx",
method: "GET",
proxy: my-vpn-proxy,
},
function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
}
);
After this, you typed the following code script:
var url = require('url');
var https = require('https');
var HttpsProxyAgent = require('https-proxy-agent');
// HTTP/HTTPS proxy to connect to
var proxy = 'my-vpn-proxy';
var endpoint = 'https://blogger.googleapis.com/v3/blogs/3213900?key=xxx';
var opts = url.parse(endpoint);
var agent = new HttpsProxyAgent(proxy);
opts.agent = agent;
https.get(opts, function (res) {
console.log('"response" event!', res.headers);
res.pipe(process.stdout);
});
Now that you have seen how you land up in the trouble. Check out how you can get the issue solved
How To Solve the Error “client network socket disconnected before secure tls connection was established”
The cause of the error is related to the proxy. We have come up with a few amazing solutions to help you get through the error warning simply. Have a look at them
Solution 1 – For Windows users
If you are using Windows operating system, then you can get rid of the error warning using the following process
- First, you need to press the Windows key on your keyboard
- Look for Internet Options
- Tap the Internet Options
- Select Connection from there
- Open LAN Settings
- In the end, you will see Use Proxy Server for LAN ….
It resolves the error. However, to get through the error permanently, you need to ensure all software should set up a proxy automatically.
Solution 2 – For Unix user
If you are a Unix user, you can simply fix the error that is related to the proxy. You just need to check the environment variables HTTPS_PROXY and HTTP_PROXY. It is an effective way to solve the error.
Conclusion
In this post, we shed light on the solutions to help you remove the error warning “client network socket disconnected before secure tls connection was established”. To fix the error, you can simply use the solution based on the operating system you are using.
I hope you find it helpful!
If you need assistance or find it really informative, then don’t hesitate to write back to us in the comment box below.