ECONNRESET error when performing a GET request - api

I'm trying to make a GET request to a REST Aviation Weather API called AVWX but after performing the request it holds for about 10 seconds and then I get the following error displayed in the console:
throw er; // Unhandled 'error' event
^
Error: read ECONNRESET
at TLSWrap.onStreamRead (node:internal/stream_base_commons:211:20)
Emitted 'error' event on ClientRequest instance at:
at TLSSocket.socketErrorListener (node:_http_client:447:9)
at TLSSocket.emit (node:events:394:28)
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
errno: -4077,
code: 'ECONNRESET',
syscall: 'read'
Here's my HTTPS.request function call:
HTTPS.request({
hostname: 'avwx.rest',
port: 443,
path: '/api/metar/KJFK',
method: 'GET',
headers: {
'Authorization': 'myToken',
},
}, res => {
console.log(`statusCode: ${res.statusCode}`);
res.on('data', d => {
process.stdout.write(d);
});
});
Thank you for your help!

As #Ever said in a comment on the question, I was missing req.end().

Related

heroku cli login 'thow err'

I am trying to login to heroku in terminal, so i type:heroku login -i
Then type in my email and get this response after:
C:\Program Files\heroku\client\node_modules\cli-ux\node_modules\#oclif\errors\lib\index.js:42
throw err;
^
CLIError: timed out
at Object.error (C:\Program Files\heroku\client\node_modules\cli-ux\node_modules\#oclif\errors\lib\index.js:26:15)
at Timeout._onTimeout (C:\Program Files\heroku\client\node_modules\#heroku-cli\command\lib\login.js:27:38)
at listOnTimeout (internal/timers.js:554:17)
at processTimers (internal/timers.js:497:7) {
oclif: { exit: 2 },
code: undefined
}
does anyone know how to fix this?

Difference between java script and node ..?

Error: querySrv ETIMEOUT _mongodb._tcp.cluster0.00g3e.mongodb.net
at QueryReqWrap.onresolve [as oncomplete] (dns.js:210:19) {
errno: undefined,
code: 'ETIMEOUT',
syscall: 'querySrv',
hostname: '_mongodb._tcp.cluster0.00g3e.mongodb.net'
}

Error: connect ECONNREFUSED 127.0.0.1:6379

I have coding like this
const redis = require("redis");
const client = redis.createClient();
client.on("connect", function() {
console.log("You are now connected");
});
client.set("student", "Laylaa", function(err, reply) {
console.log(reply);
});
but there is an error like this..
events.js:291
throw er; // Unhandled 'error' event
^
Error: connect ECONNREFUSED 127.0.0.1:6379
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1145:16)
Emitted 'error' event on RedisClient instance at:
at RedisClient.on_error (E:\TEKNIK INFORMATIKA\Latihan redis\node_modules\redis\index.js:341:14)
at Socket. (E:\TEKNIK INFORMATIKA\Latihan redis\node_modules\redis\index.js:222:14)
at Socket.emit (events.js:314:20)
at emitErrorNT (internal/streams/destroy.js:106:8)
at emitErrorCloseNT (internal/streams/destroy.js:74:3)
at processTicksAndRejections (internal/process/task_queues.js:80:21) {
errno: -4078,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 6379
}
is there a solution? Thanks
You need to first start the redis server by executing:
redis-server
in a terminal, after redis has been installed and before launching the Node.js client.
You could also add a script to your package.json:
"scripts": {
"redis": "redis-server"
}
and run:
npm run redis
On Linux Ubuntu you’ll need to run
sudo apt-get install redis-server
and Redis will automatically be up and running.Once it’s started, Redis listens on port 6379
.

Error: getaddrinfo EAI_AGAIN undefined (ldapjs)

So, i tried to deploy my Express.Js app to my vps, but I get some error that refined to Error: getaddrinfo EAI_AGAIN undefined. The weird part is, it is doing just fine if I run this app on my localhost. Any body knows how to resolve this issue?
Here are the error log that I get.
events.js:187
throw er; // Unhandled 'error' event
^
Error: getaddrinfo EAI_AGAIN undefined
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:60:26)
Emitted 'error' event on Client instance at:
at Backoff.<anonymous> (/home/user/deploy-folder/app-api/node_modules/ldapjs/lib/client/client.js:1228:12)
at Backoff.emit (events.js:210:5)
at Backoff.backoff (/home/user/deploy-folder/app-api/node_modules/ldapjs/node_modules/backoff/lib/backoff.js:41:14)
at /home/user/deploy-folder/app-api/node_modules/ldapjs/lib/client/client.js:1214:15
at f (/home/user/deploy-folder/app-api/node_modules/ldapjs/node_modules/once/once.js:25:25)
at Socket.onResult (/home/user/deploy-folder/app-api/node_modules/ldapjs/lib/client/client.js:1016:7)
at Object.onceWrapper (events.js:300:26)
at Socket.emit (events.js:210:5)
at emitErrorNT (internal/streams/destroy.js:92:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:60:3) {
errno: 'EAI_AGAIN',
code: 'EAI_AGAIN',
syscall: 'getaddrinfo',
hostname: 'undefined'
I assume that by now you discovered the error, but in this particular case it seems that the variable you are using to setup ldap is not stated or resolves to undefined.
The proper way to do it according to the documentation is this:
var ldap = require('ldapjs');
var client = ldap.createClient({
url: 'ldap://127.0.0.1:1389'
});

throw err; // Rethrow non-MySQL errors ^ Error: ER_NO_SUCH_TABLE: Table 'favicon.ico' doesn't exist

code in app.js:
const mysql = require('mysql');
const mc = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'mysql',
database: 'test0'
});
app.get('/account', function (req, res) {
mc.query('SELECT * FROM account', function (error, results, fields) {
if (error) throw error;
return res.send({ error: false, data: results, message: 'Todos list.' });
});
});
result:
the same code running well in node version 8.9, after upgrade it shown the data in browser after that thrown an error in terminal
$ node -v
v8.11.2
$ node app.js
Node app is running on port 8080
/Users/sugizo/Downloads/learn/test0/node_modules/mysql/lib/protocol/Parser.js:80
throw err; // Rethrow non-MySQL errors
^
Error: ER_NO_SUCH_TABLE: Table 'favicon.ico' doesn't exist
at Query.Sequence._packetToError (/Users/sugizo/Downloads/learn/test0/node_modules/mysql/lib/protocol/sequences/Sequence.js:52:14)
at Query.ErrorPacket (/Users/sugizo/Downloads/learn/test0/node_modules/mysql/lib/protocol/sequences/Query.js:77:18)
at Protocol._parsePacket (/Users/sugizo/Downloads/learn/test0/node_modules/mysql/lib/protocol/Protocol.js:279:23)
at Parser.write (/Users/sugizo/Downloads/learn/test0/node_modules/mysql/lib/protocol/Parser.js:76:12)
at Protocol.write (/Users/sugizo/Downloads/learn/test0/node_modules/mysql/lib/protocol/Protocol.js:39:16)
at Socket.<anonymous> (/Users/sugizo/Downloads/learn/test0/node_modules/mysql/lib/Connection.js:103:28)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
--------------------
at Protocol._enqueue (/Users/sugizo/Downloads/learn/test0/node_modules/mysql/lib/protocol/Protocol.js:145:48)
at Connection.query (/Users/sugizo/Downloads/learn/test0/node_modules/mysql/lib/Connection.js:208:25)
at /Users/sugizo/Downloads/learn/test0/app.js:35:8
at Layer.handle [as handle_request] (/Users/sugizo/Downloads/learn/test0/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/sugizo/Downloads/learn/test0/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/Users/sugizo/Downloads/learn/test0/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/Users/sugizo/Downloads/learn/test0/node_modules/express/lib/router/layer.js:95:5)
at /Users/sugizo/Downloads/learn/test0/node_modules/express/lib/router/index.js:281:22
at param (/Users/sugizo/Downloads/learn/test0/node_modules/express/lib/router/index.js:354:14)
at param (/Users/sugizo/Downloads/learn/test0/node_modules/express/lib/router/index.js:365:14)
already search in the app for 'favicon.ico', but can't found anything contain favicon.ico
any idea? thx
nice, thx, solved by
$ npm install serve-favicon --save
and modified app.js
const favicon = require('serve-favicon');
const path = require('path');
app.use(favicon(path.join(__dirname, 'public', 'images', 'favicon.ico') ) );