Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED - redis

I will already setup npm, socket.io, redis and redis-server... but I can't understand this error:
throw er; // Unhandled 'error' event
^
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.
1:6379
at Object.exports._errnoException (util.js:1016:11)
at exports._exceptionWithHostPort (util.js:1039:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1138:14)
Code:
var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);
var redis = require('redis');
server.listen(8890);
io.on('connection', function (socket) {
console.log("client connected");
var redisClient = redis.createClient();
redisClient.subscribe('message');
redisClient.on("message", function(channel, data) {
console.log("new message add in queue "+ data['message'] + " channel");
socket.emit(channel, data);
});
socket.on('disconnect', function() {
redisClient.quit();
});
});

redis.createClient() tries to connect to the local machine's redis server and try on the port number 6379. For this you need to start the redis server with the following command.
redis-server

Related

How do I connect my database to local SQL Server Express using nose js

I am using Express framework and trying to connect to my SQL Server Express database locally. I am getting error - connection failure. I need help with that, if you'd please.
Steps completed so far..
npm install mssql
var sql = require("mssql");
// config for your database
var config = {
user: 'ImacamUser',
password: '*****',
server: 'localhost',
database: 'InvoicingData'
};
sql.connect(config, (err) => {
if (err) console.log(err);
// create Request object
var request = new sql.Request();
// query to the database and get the records
request.query('select * from Customers', function (err, recordset) {
if (err) console.log(err)
// send records as a response
res.send(recordset);
});
});
The error I get from this code is:
ConnectionError: Failed to connect to localhost:1433 - Could not connect (sequence)
at C:\Projects\RCN\Invoicing\node_modules\mssql\lib\tedious\connection-pool.js:70:17
at Connection.onConnect (C:\Projects\RCN\Invoicing\node_modules\tedious\lib\connection.js:1012:9)
at Object.onceWrapper (node:events:510:26)
at Connection.emit (node:events:390:28)
at Connection.emit (C:\Projects\RCN\Invoicing\node_modules\tedious\lib\connection.js:1040:18)
at Connection.socketError (C:\Projects\RCN\Invoicing\node_modules\tedious\lib\connection.js:1395:12)
at C:\Projects\RCN\Invoicing\node_modules\tedious\lib\connection.js:1176:14
at processTicksAndRejections (node:internal/process/task_queues:78:11) {
code: 'ESOCKET',
originalError: ConnectionError: Failed to connect to localhost:1433 - Could not connect (sequence)
at Connection.socketError (C:\Projects\RCN\Invoicing\node_modules\tedious\lib\connection.js:1395:28)
at C:\Projects\RCN\Invoicing\node_modules\tedious\lib\connection.js:1176:14
at processTicksAndRejections (node:internal/process/task_queues:78:11) {
code: 'ESOCKET',
isTransient: undefined
}
Any help would be appreciated.

RabbitMQ: connect ECONNREFUSED error. Cant connect to the 5672 port

I am trying to learn RabbitMQ. I am using the following code that I got from tutorials:
publisher.js:
const amqp = require("amqplib/callback_api");
amqp.connect(`amqp://localhost`, (err, connection) => {
if (err) throw err;
connection.createChannel((err, channel) => {
const queueName = 'queue';
const message = 'This is the message to send'
channel.assertQueue(queueName, {
durable:false,
});
channel.sendToQueue(queueName, Buffer.from(message));
console.log('Message: ' + message);
setTimeout(()=>{
connection.close();
}, 1000);
});
});
When I run publisher.js using node in the CLI, I get this error:
Error: connect ECONNREFUSED ::1:5672
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1300:16) {
errno: -61,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '::1',
port: 5672
}
I was expecting:
Console log with the message
Message should also be added to the queue
Is it a TCP connection or firewall issue? If so, how can I fix it?
Instead of localhost, use 127.0.0.1
That should fix the problem.

Error: self-signed certificate When connecting to google FCM with XMPP protocol

I am trying to connect to google Firebase Messaging with xmpp protocol with Node Js with node-xmpp-client
But I am getting an TLS error
Below is the code:
const XMPP = require("node-xmpp-client");
config = {
id: "push-notify-xmpp",
key: "________KEY______",
port: "5236",
host: "fcm-xmpp.googleapis.com",
};
client = new XMPP.Client({
jid: `${config.id}#fcm-xmpp.googleapis.com`,
password: config.key,
port: config.port,
host: config.host,
legacySSL: true,
preferredSaslMechanism: "PLAIN",
});
client.connection.socket.on("error", function (error) {
console.log("socket error");
console.error(error);
process.exit(1);
});
client.on("online", function (data) {
console.log(
"Connected as " +
data.jid.local +
"#" +
data.jid.domain +
"/" +
data.jid.resource
);
});
client.on("error", function (err) {
console.log("server error");
console.error(err);
process.exit(1);
});
Error:
server error
Error: self-signed certificate
at TLSSocket.onConnectSecure (node:_tls_wrap:1538:34)
at TLSSocket.emit (node:events:513:28)
at TLSSocket._finishInit (node:_tls_wrap:952:8)
at ssl.onhandshakedone (node:_tls_wrap:733:12) {
code: 'DEPTH_ZERO_SELF_SIGNED_CERT'
}
Also tried the command :
NODE_TLS_REJECT_UNAUTHORIZED='0' node appServer.js
But above get an different error Unauthorised
Can Anyone have any Idea ow to deal with FCM server with XMPP

Peerjs keeps loosing connection and user id is lost

I have made an application following a tutorial using peerjs. Everything seems to be working fine except when I make a connection for a video call where I am using peerjs. I have made my own peerjs server which I am running on localhost (right now for testing). Here is the code for the peer server:
const express = require('express');
const path = require('path');
const http = require('http');
const cors = require('cors');
const errorhandler = require('errorhandler');
var ExpressPeerServer = require('peer').ExpressPeerServer;
var options = {
debug: true,
key: 'copycat'
};
var app = express();
var server = http.createServer(app);
var port = process.env.PORT || '3001';
app.set('port', port);
app.use(cors());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/peerjs', ExpressPeerServer(server, options));
app.use(errorhandler());
process.on('uncaughtException', function(exc) {
console.error(exc);
});
server.listen(port);
As you can see I am running the app on port 3001. Now following is the script for peerjs connection for a video call:
// PeerJS
// Compatibility shim
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
// PeerJS object
var peer = new Peer(username + roomId, {
host: 'localhost',
path: '/peerjs',
port: 443,
secure: true,
key: 'copycat',
debug: true
});
peer.on('open', function () {
$('#my-id').text(peer.id);
});
// Receiving a call
peer.on('call', function (call) {
// Answer the call automatically (instead of prompting user) for demo purposes
call.answer(window.localStream);
step3(call);
});
peer.on('error', function (err) {
alert(err.message);
// Return to step 2 if error occurs
step2();
});
// Click handlers setup
$(function () {
$('#make-call').click(function () {
// Initiate a call!
var call = peer.call($('#callto-id').val(), window.localStream);
step3(call);
});
$('#end-call').click(function () {
window.existingCall.close();
step2();
});
step1();
});
function step1() {
// Get audio/video stream
navigator.getUserMedia({ audio: true, video: true }, function (stream) {
// Set your video displays
$('#my-video').prop('src', URL.createObjectURL(stream));
window.localStream = stream;
step2();
}, function () { $('#step1-error').show(); });
}
function step2() {
$('#step1, #step3').hide();
$('#step2').show();
}
function step3(call) {
// Hang up on an existing call if present
if (window.existingCall) {
window.existingCall.close();
}
// Wait for stream on the call, then set peer video display
call.on('stream', function (stream) {
$('#second-video').prop('src', URL.createObjectURL(stream));
});
// UI stuff
window.existingCall = call;
$('#second-id').text(call.peer);
call.on('close', step2);
$('#step1, #step2').hide();
$('#step3').show();
}
This is pretty much the example code from peerjs example file on github. What I am confused about is the port value. Inside the options in the above script its port 443. I get the following error in chrome when I try to make a video call:
peer.js:1492 WebSocket connection to 'wss://localhost/peerjs/peerjs?key=peerjs&id=User80925be509c6c606fa21409858f5&token=zz69b3ccyk' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
Socket._startWebSocket # peer.js:1492
Socket.start # peer.js:1481
Peer._initialize # peer.js:1058
Peer # peer.js:962
(anonymous) # 5be509c6c606fa21409858f5:183
peer.js:1741 PeerJS: Socket closed.
peer.js:1741 PeerJS: ERROR Error: Lost connection to server.
peer.js:1555 POST https://localhost/peerjs/peerjs/User80925be509c6c606fa21409858f5/zz69b3ccyk/id?i=0 net::ERR_CONNECTION_REFUSED
Socket._startXhrStream # peer.js:1555
Socket.start # peer.js:1480
Peer._initialize # peer.js:1058
Peer # peer.js:962
(anonymous) # 5be509c6c606fa21409858f5:183
peer.js:1741 PeerJS: ERROR Error: Lost connection to server.
Please advise what am I doing wrong???
If you are using at your local end then use your localport i.e. 3001 else use 443
make object like this
var peer = new Peer(undefined, {
host: 'localhost',
path: '/peerjs',
port: 3001,
secure: true,
key: 'copycat',
debug: true
});

How to authenticate rabbitmq in nodejs?

Error: Handshake terminated by server: 403 (ACCESS-REFUSED) with message "ACCESS_REFUSED - Login was refused using authen
tication mechanism PLAIN. For details see the broker logfile."
I tried authMechanism individually ('PLAIN', 'AMQPLAIN', 'EXTERNAL') but i'm getting same error.
Unable to create connection with rabbitMQ
var raabitmqSettings = {
protocol: 'amqp',
hostname: '10.250.18.31',
port: 5672,
username: 'sam',
password: 'sam#123',
vhost: '/',
authMechanism: ['PLAIN', 'AMQPLAIN', 'EXTERNAL']
}
amqp.connect(raabitmqSettings, function(err, conn) {
conn.createChannel(function(err, ch) {
console.log("\n\n" + ch);
}
}
Where can i see log file in rabbit mq or how enable logs in rabbitMQ?
Is it right way to create connection? Is there any setting in rabbitMQ server?
Use following code at receiver end
const open = await amqp.connect(setting);
var ch = await open.createChannel();
await ch.assertExchange("cronService", "direct");
var q = 'CronQueue';
ch.assertQueue(q, { durable: true });
ch.consume(q, async function(msg) {
console.log(" [x] Received %s", msg.content.toString());
}, { noAck: true });
return something;