syscall: 'write', code: 'EPROTO', errno: -4046, or AxiosError: read ECONNRESET - node.js

I am trying to test out using proxies for the first time in my coding career and been trying for a while now. However I keep getting this weird error that doesnt make any sense in my head. The proxy I use here is taken from http://free-proxy.cz/en/proxylist/country/US/https/date/all. I have no problem paying for some proxy servers I just wanna make sure it works before paying for anything.
However I keep getting the error AxiosError: read ECONNRESET OR AxiosError: Client network socket disconnected before secure TLS connection was established OR write EPROTO E0DA0000:error:0A00010B:SSL routines:ssl3_get_record:wrong version number:c:\ws\deps\openssl\openssl\ssl\record\ssl3_record.c:355:
I am running the code on Localhost so my connection to the proxy server is not https.
Here is the code I am trying to excecute. I have imported
var HttpsProxyAgent = require('https-proxy-agent');
But this clearly is not the problem.
router.get("/userInvTest", async (req, res) => {
try {
const axiosDefaultConfig = {
proxy: false,
httpsAgent: new HttpsProxyAgent('https://205.134.235.132:3129'),
};
const axiosUse = require('axios').create(axiosDefaultConfig);
const steamInventory = await axiosUse.get("https://steamcommunity.com/inventory/76561198027016127/730/2?l=english&count=5000");
console.log(steamInventory.data)
res.status(200).send(steamInventory.data)
} catch (err) {
console.log(err)
}
})

Related

TypeError: Cannot read property 'body' of null

Struggling to get this one to work now;
const superagent = require("snekfetch");
const Discord = require('discord.js')
module.exports = {
name: "cat",
category: "fun",
description: "Sends a random image of a cat",
usage: "[command]",
run: async (client, message, args, level) => {
//command
superagent.get('https://nekos.life/api/v2/img/meow')
.end((err, response) => {
const lewdembed = new Discord.MessageEmbed()
.setTitle("Random cat")
.setImage(response.body.url)
.setColor(`#00FF00`)
.setFooter(`owo`)
.setURL(response.body.url);
message.channel.send(lewdembed);
})
}
};
Throwing up this error;
TypeError: Cannot read property 'body' of null
at /home/runner/Manias-Bot/commands/fun/cat.js:16:22
at /home/runner/Manias-Bot/node_modules/snekfetch/src/index.js:212:22
I can see the error is with (response.body.url), but unsure how to solve this. Any help?
Firstly, snekfetch has been deprecated, you should use node-fetch instead.
See https://www.npmjs.com/package/snekfetch
Secondly, the error is because response is null - almost certainly because you have an error when trying to get that resource. My guess would be ECONNREFUSED but you can confirm this by checking the value of err and response in your get, i.e.
superagent.get('https://nekos.life/api/v2/img/meow')
.end((err, response) => {
console.log(err, response)
})
This give me...
[Error: connect ECONNREFUSED 0.0.0.0:443] {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '0.0.0.0',
port: 443
} null
So as you can see - the server is refusing the request and the response is null
To fix this you should use a package that isn't deprecated and make sure you are trying to fetch a resource that you have permission/access to get.
When fetching anything - it is always a good idea to check to see if there are any errors before trying to do something with the expected result.

Executing ksql query using node npm ksqlDb-client throwing an timeout error

Hi am trying to execute the KSQL query using npm package ksqlDb-client package, it throws an timeout error. I have attached the code as well, please let me know any issues over there.
when am hit this GET URL below method will execute https://localhost:5000/testKsql
exports.getKSQLStream = async () => {
const options = {
authorization: {
username: "admin",
password: "pw",
ssl: {
ca: CAs,
crt: myClientCert,
key: myClientKey,
}
},
host: 'https://ixxxx.xcxx.net',
timeout: 20000
}
const client = new KsqldbClient(options);
await client.connect();
const streamRes = await client.query('list streams;');
console.log("streams",streamRes);
await client.disconnect();
}
when I hit that URL from postman am getting below response in node console.
Error on Http2 client. Error: connect ETIMEDOUT 16.2XX.X4.xxx:8088
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1159:16) {
errno: -4039,
code: 'ETIMEDOUT',
syscall: 'connect',
address: '16.2XX.X4.xxx',
port: 8088
}
I faced recently with the same issue and found that library has bug with authorization. I pushed PR in repo, but you can patch your local copy in the same way.
https://github.com/Streaminy/ksqldb-client/pull/4

Error: read ECONNRESET while connection rabbitmq with nodejs

I've encountered following error message while connection our external RabbitMQ with NodeJS as follow:
Error: read ECONNRESET
at TCP.onStreamRead (internal/stream_base_commons.js:205:27) {
errno: 'ECONNRESET',
code: 'ECONNRESET',
syscall: 'read'
}
and my nodejs code is as follow:
const amqp_url = "amqp://un:pw#sb-mq.com:9901/my-vhost";
amqp.connect(amqp_url, function (error0, connection) {
if (error0) {
throw error0;
}
connection.createChannel(function (error1, channel) {
if (error1) {
throw error1;
}
var queue = 'hello';
var msg = 'Hello World!';
channel.assertQueue(queue, {
durable: false
});
channel.sendToQueue(queue, Buffer.from(msg));
console.log(" [x] Sent %s", msg);
});
setTimeout(function () {
connection.close();
process.exit(0);
}, 500);
});
But the thing is when I've setup RabbidMQ locally with same configuration but using default port (like amqp://un:pw#localhost:5672/my-vhost), it was working perfectly. Please let me know how to troubleshoot that one, thanks.
"ECONNRESET" means the other side of the TCP conversation abruptly closed its end of the connection.
see How do I debug error ECONNRESET in Node.js?
about RabbitMQ check if rabbitmq actually is active in that port, just:
telnet sb-mq.com 9901
from your client machine and check the firewall configuration.
You may have another service running on 9901
ECONNRESET is network problem, rabbitmq can work in different ports without problems
I found that issue has been resolved when I've tried to use amqps instead of amqp.

How to run Vault from my app instead of CLI?

I'm trying to start a Vault service in my NodeJS app.
Using CLI to use Vault is ok,
but i need it to work automatically when the app is started.
I try this
async started(ctx) {
var options = {
apiVersion: 'v1', // default
endpoint: 'http://127.0.0.1:8500', // default
};
// get new instance of the client
var vault = require("node-vault")(options);
// init vault server
vault.init({ secret_shares: 1, secret_threshold: 1 })
.then( (result) => {
var keys = result.keys;
// set token for all following requests
vault.token = result.root_token;
// unseal vault server
return vault.unseal({ secret_shares: 1, key: keys[0] })
})
.catch(console.error);
// see if it is ok
vault.status()
.then (res => {
console.log('STATuuuuuuuuuuusS', res);
})
.catch((err) => {
console.log("errrrrrreur status");
console.error(err.message);
});
But i've got this error:
RequestError: Error: connect ECONNREFUSED 127.0.0.1:8500
[...]
cause: Error: connect ECONNREFUSED 127.0.0.1:8500
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16) {
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 8500
},
If i run this before, it worked
vault server -config=config.hcl
Even when i kill it, it seems to work without reloading it. I'm missing something here, for sure :)
I'm wondering if node-vault should start Vault server ? If not, i'm wondering how to start the Vault server from the app and not the CLI ?
If you know the good way to do it, or have clues, i'm all ears.
Nicolas
No, usually the code shouldn't start the server.
Yes, your code is working correctly. If you have not started the server, the error means that it is impossible to connect to the specified IP address and port, they are closed.
The vault server has nothing to do with it, the same behavior will be the database server or any other.

Node.js Error : connect ECONN Refused

I am new to Node.js and am unable to resolve this error:
Error: connect ECONNREFUSED
at errnoException (net.js:901:11)
at Object.afterConnect (as oncomplete) (net.js:892)
The code I was trying out follows :
var async = require('async'),
request = require('request');
function done(err,results) {
if (err) {
throw err;
}
console.log('Done ! results: %j',results);
}
var collection = [1,2,3,4];
function iterator(value,callback) {
request.post({
url: 'http://localhost:8080',
body: JSON.stringify(value)
}, function (err,res,body){
if (err) {
callback(err,body && JSON.parse(body));
}
});
}
async.map(collection,iterator,done);
ECONNREFUSED – Connection refused by server error
A port is being blocked can be the root cause of this issue, check if your connection is being blocked or even the changed default port can also cause this issue. Identify which app/service you are connecting to and its port is being blocked or changed.
And in your case check whether the application is hosted on port: 8080 or not.
But, this most likely occurs with FileZilla.

Resources