connect ECCONREFUSED ::1:50106 - javascript

I'm making a discord bot with Node.js and erela.js, but when I try to get the server that handles erela on, it shows me this error:
A node error occured: connect ECONNREFUSED ::1:50106
2020-05-01T21:23:19.367157+00:00 app[worker.1]: events.js:287
2020-05-01T21:23:19.367175+00:00 app[worker.1]: throw er; // Unhandled 'error' event
2020-05-01T21:23:19.367176+00:00 app[worker.1]: ^
2020-05-01T21:23:19.367176+00:00 app[worker.1]:
2020-05-01T21:23:19.367177+00:00 app[worker.1]: Error: connect ECONNREFUSED ::1:50106
2020-05-01T21:23:19.367178+00:00 app[worker.1]: at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)
2020-05-01T21:23:19.367179+00:00 app[worker.1]: Emitted 'error' event on WebSocket instance at:
2020-05-01T21:23:19.367179+00:00 app[worker.1]: at ClientRequest.<anonymous> (/app/node_modules/ws/lib/websocket.js:554:15)
2020-05-01T21:23:19.367179+00:00 app[worker.1]: at ClientRequest.emit (events.js:310:20)
2020-05-01T21:23:19.367180+00:00 app[worker.1]: at Socket.socketErrorListener (_http_client.js:426:9)
2020-05-01T21:23:19.367181+00:00 app[worker.1]: at Socket.emit (events.js:310:20)
2020-05-01T21:23:19.367181+00:00 app[worker.1]: at emitErrorNT (internal/streams/destroy.js:92:8)
2020-05-01T21:23:19.367181+00:00 app[worker.1]: at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
2020-05-01T21:23:19.367182+00:00 app[worker.1]: at processTicksAndRejections (internal/process/task_queues.js:84:21) {
2020-05-01T21:23:19.367185+00:00 app[worker.1]: errno: 'ECONNREFUSED',
2020-05-01T21:23:19.367185+00:00 app[worker.1]: code: 'ECONNREFUSED',
2020-05-01T21:23:19.367185+00:00 app[worker.1]: syscall: 'connect',
2020-05-01T21:23:19.367186+00:00 app[worker.1]: address: '::1',
2020-05-01T21:23:19.367186+00:00 app[worker.1]: port: 50106
The index.js code is:
const discord = require("discord.js");
const fs = require("fs");
const bot = new discord.Client({disableEveryone: true});
const prefix = "."
const token = process.env.token;
const { ErelaClient } = require('erela.js');
function server () {
require ("./server.js");
}
// When bot ready
bot.on("ready", async () => {
server();
bot.music = new ErelaClient(bot, [
{
host: process.env.HOST,
port: process.env.PORT,
password: process.env.PASSWORD
}
]);
bot.music.on("nodeConnect", node => console.log("New node connected, music is now working on the bot!"));
bot.music.on("nodeError", (node, error) => console.log(`A node error occured: ${error.message}`));
And the server.js code is:
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('Hello World!');
});
app.listen(7000, function () {
console.log('Example app listening on port 7000, so erela will work!');
});
I don't know why it's happening. If someone has an answer for this. I'd be grateful

If you have two servers running on the same PC, you should enable CORS to allow communications between both of them.
Add in the server.js file:
const cors = require('cors')
app.use(cors())
Also, install in CLI:
npm install cors
CORS npm link
Hope this can help you.

Related

Fetch Error while getting data from food-data-central API

So I am trying to get some data from the food-data-central API. In my program I console log the data, but I don't get any results on the console.
The only thing I get is an error about Fetch Error
import fetch from "node-fetch"
const params = {
api_key: <apiKey>,
query: 'chicken breast raw',
dataType: ["Survey (FNDDS)"],
pagesize: 5,
}
const api_url = `https://api.nal.usda.gov/fdc/v1/foods/search?api_key=${encodeURIComponent(params.api_key)}&query=${encodeURIComponent(params.query)}&dataType=${encodeURIComponent(params.dataType)}&pageSize=${encodeURIComponent(params.pagesize)}`
function getData(){
return fetch(api_url).then(response => response.json())
}
getData().then(data => {
const foods = data.foods[0];
console.log("Protein: ");
console.log(foods.foodNutrients[0].value);
console.log("Fats: ");
console.log(foods.foodNutrients[1].value);
console.log("Carbs: ");
console.log(foods.foodNutrients[2].value);
});
The output that I get:
reject(new FetchError(`request to ${request.url} failed, reason: ${err.message}`, 'system', err));
^
FetchError: request to https://api.nal.usda.gov/fdc/v1/foods/search?api_key=3Bi6rNu3MiTYMaPwMf2u5vs1xAtdKS0n5HoFpgy9&query=chicken%20breast%20raw&dataType=Survey%20(FNDDS)&pageSize=5 failed, reason: connect ETIMEDOUT 2600:1f12:18a:7d00:217:68d:2c2:3718:443
at ClientRequest.<anonymous> (/home/dflorian251/Desktop/node_modules/node-fetch/lib/index.js:1505:11)
at ClientRequest.emit (node:events:513:28)
at TLSSocket.socketErrorListener (node:_http_client:481:9)
at TLSSocket.emit (node:events:513:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
type: 'system',
errno: 'ETIMEDOUT',
code: 'ETIMEDOUT'
Is something wrong with the node-fetch module ?

I have a problem with getting started sequelize with postgres

i wrote this code from sequelize documentation.
i created a databade in pgadmin with the name of users and pasword 12345 and o thought it should be connected to the db. but it does not. at first it write the " Connection has been established successfully. "
in the terminal but then i catch an error.
const { Sequelize } = require('sequelize');
const sequelize = new Sequelize('postgres://Admin:12345:5432/users')
try {
sequelize.authenticate();
console.log('Connection has been established successfully.');
} catch (error) {
console.error('Unable to connect to the database:', error);
}
the error:
reject(new sequelizeErrors.HostNotFoundError(err));
^
HostNotFoundError [SequelizeHostNotFoundError]: getaddrinfo ENOTFOUND admin
at Client._connectionCallback (C:\Users\moham\OneDrive\Desktop\jalese1\node_modules\sequelize\lib\dialects\postgres\connection-manager.js:133:24)
at Client._handleErrorWhileConnecting (C:\Users\moham\OneDrive\Desktop\jalese1\node_modules\pg\lib\client.js:305:19)
at Client._handleErrorEvent (C:\Users\moham\OneDrive\Desktop\jalese1\node_modules\pg\lib\client.js:315:19)
at Connection.emit (node:events:527:28)
at Socket.reportStreamError (C:\Users\moham\OneDrive\Desktop\jalese1\node_modules\pg\lib\connection.js:52:12)
at Socket.emit (node:events:527: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) {
parent: Error: getaddrinfo ENOTFOUND admin
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:26) {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'admin'
},
original: Error: getaddrinfo ENOTFOUND admin
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:26) {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'admin'
}
}
where is the problem?

node.js net.connect() error in spite of try-catch

This code is producing an error in spite of a try-catch block... It should send a error message, if the server isn't reachable and a positive message, if ist is.
try {
net.connect(25565, "mc.hypixel.net", () => {
console.log("connected");
});
} catch (err) {
console.log("not connected");
}
This is the error:
events.js:292
throw er; // Unhandled 'error' event
^
Error: connect ETIMEDOUT 104.16.78.21:25565
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
Emitted 'error' event on Socket instance at:
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: -4039,
code: 'ETIMEDOUT',
syscall: 'connect',
address: '104.16.78.21',
port: 25565
}
Thank you for your help :)
hmm.. I believe the following answer is what net suggests
try this
net.connect(25565, "mc.hypixel.net", () => {
console.log("connected");
})
.on('error', (err)=>console.log("not connected"));

No stream features to proceed using node-xmpp-client

I've installed prosody on an ubuntu AWS server. I have tried using Adium client and swift, but I get the same error indicated in the title. I've tried using node-xmpp-client to create a client but same error.
Node-XMPP client code:
const Client = require('node-xmpp-client');
const options = {
jid: 'test#ec2-18-222-249-134.us-east-2.compute.amazonaws.com',
password: 'password',
host: 'ec2-18-222-249-134.us-east-2.compute.amazonaws.com'
}
const client = new Client(options);
client.once('online', connectionDetails =>{
console.log('We are connected');
console.log(connectionDetails);
});
Error Message:
Error: No stream features to proceed with
at Connection.onStanza (/Users/my-name/BeginXMPP/node_modules/node-xmpp-core/lib/Connection.js:363:17)
at StreamParser.<anonymous> (/Users/my-name/BeginXMPP/node_modules/node-xmpp-
core/lib/Connection.js:231:10)
at StreamParser.emit (events.js:198:13)
at SaxLtx.<anonymous> (/Users/my-name/BeginXMPP/node_modules/#xmpp/streamparser/index.js:69:14)
at SaxLtx.emit (events.js:198:13)
at SaxLtx._handleTagOpening (/Users/my-name/BeginXMPP/node_modules/ltx/lib/parsers/ltx.js:40:12)
at SaxLtx.write (/Users/my-name/BeginXMPP/node_modules/ltx/lib/parsers/ltx.js:159:18)
at StreamParser.write (/Users/my-name/BeginXMPP/node_modules/#xmpp/streamparser/index.js:134:17)
at Connection.onData (/Users/my-name/BeginXMPP/node_modules/node-xmpp-core/lib/Connection.js:310:17)
at Socket.emit (events.js:203:15)
Emitted 'error' event at:
at Client.<anonymous> (/Users/my-name/BeginXMPP/node_modules/node-xmpp-client/lib/Client.js:158:23)
at Connection.emit (events.js:203:15)

Sequelize Connection Error when creating model

When I execute this program everything works fine:
const Sequelize = require("sequelize");
const Conn = new Sequelize("data","postgresql","postgresql", {
'host' : "localhost",
'dialect' : "postgres",
'port' : "1337"
})
// piece of code to be added here
Conn.sync().then(function(){
console.log('DB connection sucessful.');
}, function(err){
console.log(err);
});
the Console logs: DB connection successful.
When I add this line however:
const User = Conn.define('user', {
firstName: {
type: Sequelize.STRING
},
lastName: {
type: Sequelize.STRING
}
});
I get this error message:
{ SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:1337
at connection.connect.err (G:\projects\investcrypto\node_modules\sequelize\lib\dialects\postgres\connection-manager.js:95:24)
at Connection.connectingErrorHandler (G:\projects\investcrypto\node_modules\pg\lib\client.js:123:14)
at emitOne (events.js:115:13)
at Connection.emit (events.js:210:7)
at Socket.<anonymous> (G:\projects\investcrypto\node_modules\pg\lib\connection.js:71:10)
at emitOne (events.js:115:13)
at Socket.emit (events.js:210:7)
at emitErrorNT (internal/streams/destroy.js:64:8)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
name: 'SequelizeConnectionRefusedError',
parent:
{ Error: connect ECONNREFUSED 127.0.0.1:1337
at Object.exports._errnoException (util.js:1024:11)
at exports._exceptionWithHostPort (util.js:1047:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1150:14)
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 1337 },
original:
{ Error: connect ECONNREFUSED 127.0.0.1:1337
at Object.exports._errnoException (util.js:1024:11)
at exports._exceptionWithHostPort (util.js:1047:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1150:14)
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 1337 } }
Versions:
npm: 5.3.0
node: 8.2.1
sequelize: 4.8.3
pg: 7.3.0
pg-hstore 2.3.2
Try making the port 5432. That is the default port for postgres. Make sure the database data was created by the user postgresql and that the password is indeed postgresql. Depending how the DB was created you might be able to just set username and password to null
Also, the Sequelize cli is really helpful for doing a lot of the boiler plate code

Categories