Discord js keyv throwing ECONNREFUSED - node.js

I'm trying to use Keyv, following this tutorial: https://discordjs.guide/keyv/#command-handler and I'm using the command handler code as well.
In my index.js, I run something like this: (with the appropriate imports for Keyv of course)
const Keyv = require('keyv');
const mykeyv = new Keyv('redis://user:pass#localhost:6379');
client.on('message', message =>{
...//skipping some command handler stuff
command.execute(message, args, mykeyv)
})
And then when I run this, I initially get the correct and expected client.on('ready') messages, but then a few seconds after the following error pops up:
events.js:292
throw er; // Unhandled 'error' event
^
Error: connect ECONNREFUSED 127.0.0.1:6379
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)
Emitted 'error' event on Keyv instance at:
at KeyvRedis.<anonymous> (C:\Users\Meroper80\Documents\GitHub\DndBot\Node-Js-Discord-Bot\node_modules\keyv\src\index.js:43:44)
at KeyvRedis.emit (events.js:315:20)
at Redis.<anonymous> (C:\Users\Meroper80\Documents\GitHub\DndBot\Node-Js-Discord-Bot\node_modules\#keyv\redis\src\index.js:17:38)
at Redis.emit (events.js:315:20)
at Redis.silentEmit (C:\Users\Meroper80\Documents\GitHub\DndBot\Node-Js-Discord-Bot\node_modules\ioredis\built\redis\index.js:499:26)
at Socket.<anonymous> (C:\Users\Meroper80\Documents\GitHub\DndBot\Node-Js-Discord-Bot\node_modules\ioredis\built\redis\event_handler.js:186:14)
at Object.onceWrapper (events.js:422:26)
at Socket.emit (events.js:315:20)
at emitErrorNT (internal/streams/destroy.js:92:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 6379
}
I'm not sure what this error is about, can someone help me?

Related

Error [ERR_STREAM_WRITE_AFTER_END]: write after end ExpressJS

I forked a repo I found and running it locally was fine with no errors however I wanted to run it locally on https so I changed the code of src/index.js
const server = createServer();
to
const options = {
key: fs.readFileSync('localhost-key.pem'),
cert: fs.readFileSync('localhost.pem')
};
const server = https.createServer(options, app)
But I started getting the error after the change when I try to access the website on https://localhost:8080
Full Error:
node:events:491
throw er; // Unhandled 'error' event
^
Error [ERR_STREAM_WRITE_AFTER_END]: write after end
at new NodeError (node:internal/errors:399:5)
at write_ (node:_http_outgoing:868:11)
at ServerResponse.write (node:_http_outgoing:827:15)
at ReadStream.ondata (node:internal/streams/readable:766:22)
at ReadStream.emit (node:events:513:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Readable.push (node:internal/streams/readable:234:10)
at node:internal/fs/streams:275:14
at FSReqCallback.wrapper [as oncomplete] (node:fs:681:5)
Emitted 'error' event on ServerResponse instance at:
at ServerResponse.onerror (node:internal/streams/readable:785:14)
at ServerResponse.emit (node:events:525:35)
at emitErrorNt (node:_http_outgoing:846:9)
at process.processTicksAndRejections (node:internal/process/task_queues:83:21) {
code: 'ERR_STREAM_WRITE_AFTER_END'
}

Error: connect ECONNREFUSED 127.0.0.1:6379 at TCPConnectWrap.afterConnect [as oncomplete]

I have run the server and getting an error as:
events.js:292
throw er; // Unhandled 'error' event
^
Error: connect ECONNREFUSED 127.0.0.1:6379
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
Emitted 'error' event on Queue instance at:
at RedisClient.<anonymous> (C:\Users\DELL\Documents\Vs Code Folders\Feelare\node_modules\kue\lib\redis.js:65:13)
at RedisClient.emit (events.js:315:20)
at RedisClient.on_error (C:\Users\DELL\Documents\Vs Code Folders\Feelare\node_modules\redis\index.js:401:14)
at Socket.<anonymous> (C:\Users\DELL\Documents\Vs Code Folders\Feelare\node_modules\redis\index.js:279:14)
at Socket.emit (events.js:315:20)
at emitErrorNT (internal/streams/destroy.js:106:8)
at emitErrorCloseNT (internal/streams/destroy.js:74:3)
errno: -4078,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 6379
}
My Code is as:
const env = require('./environment');
mongoose.connect(`mongodb://localhost/${env.db}`);
const db = mongoose.connection;
db.on('error', console.error.bind(console, "Error connecting to MongoDB"));
db.once('open', function(){
console.log('Connected to Database :: MongoDB');
});
module.exports = db;
I have tried by installing redis and adding it into script but error is same.And also tried in production and development environment but the error is same.
This issue seems to be with redis server. Try running redis-server in the terminal.
Hope this helps!

Server crashes whenever I attempt to login MongoDB, Node.JS

I'm trying to access my localserver, whenever I attempt to start the site and login, it crashes and I get a few different errors that I've posted below.
MongoNetworkError: failed to connect to server [127.0.0.1:27017] on first connect [Error: connect ECONNREFUSED 127.0.0.1:27017
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1137:16) {
name: 'MongoNetworkError',
[Symbol(mongoErrorContextSymbol)]: {}
}]
at Pool.<anonymous> (/Users/user/dev/P2/frontpage/node_modules/mongodb/lib/core/topologies/server.js:438:11)
at Pool.emit (events.js:311:20)
at /Users/user/dev/P2/frontpage/node_modules/mongodb/lib/core/connection/pool.js:561:14
at /Users/user/dev/P2/frontpage/node_modules/mongodb/lib/core/connection/pool.js:994:11
at /Users/user/dev/P2/frontpage/node_modules/mongodb/lib/core/connection/connect.js:31:7
at callback (/Users/user/dev/P2/frontpage/node_modules/mongodb/lib/core/connection/connect.js:264:5)
at Socket.<anonymous> (/Users/user/dev/P2/frontpage/node_modules/mongodb/lib/core/connection/connect.js:294:7)
at Object.onceWrapper (events.js:418:26)
at Socket.emit (events.js:311:20)
at emitErrorNT (internal/streams/destroy.js:92:8) {
name: 'MongoNetworkError',
[Symbol(mongoErrorContextSymbol)]: {}
}
I've tried re-installing Mongo but with no luck.
Thanks

MongoNetworkError: connection 5 to ercluster-shard-00-01-8xhj2.mongodb.net:27017 timed out

I am using react and nodejs.When i send query to mongodb , after some time (2-3 min) i am geting this error(MongoNetworkError timed out). I am using cluster that i created on mongo atlas.
I tried to create new account and cluster on mongo atlas , set up new mongo uri ,but the problem is same.
console.log("mongoUri:", config.mongoUri);
const options = {
useNewUrlParser: true
// keepAlive: 300000,
// connectTimeoutMS: 30000
};
mongoose.connect(config.mongoUri, options, err => {
console.log("error occured", err);
});
console.log("mongoose connection:", mongoose.connection.readyState);
mongoose.connection.readyState;
error occured { MongoNetworkError: connection 4 to etcluster-shard-00-01-u7zep.mongodb.net:27017 timed
out
at TLSSocket.<anonymous> (C:\Users\Petar\Documents\GitHub\eliteranks\elite-ranks-back\node_modules\mongoose\node_modules\mongodb-core\lib\connection\connection.js:335:7)
at Object.onceWrapper (events.js:273:13)
at TLSSocket.emit (events.js:182:13)
at TLSSocket.Socket._onTimeout (net.js:449:8)
at ontimeout (timers.js:436:11)
at tryOnTimeout (timers.js:300:5)
at listOnTimeout (timers.js:263:5)
at Timer.processTimers (timers.js:223:10)
name: 'MongoNetworkError',
errorLabels: [ 'TransientTransactionError' ],
[Symbol(mongoErrorContextSymbol)]: {} }
events.js:167
throw er; // Unhandled 'error' event
^
Error: read ECONNRESET
at TLSWrap.onStreamRead (internal/stream_base_commons.js:111:27)
Emitted 'error' event at:
at TLSSocket.<anonymous> (C:\Users\Petar\Documents\GitHub\eliteranks\elite-ranks-back\node_modules\mongoose\node_modules\mongodb-core\lib\connection\connection.js:321:10)
at Object.onceWrapper (events.js:273:13)
at TLSSocket.emit (events.js:182:13)
at emitErrorNT (internal/streams/destroy.js:82:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
at process._tickCallback (internal/process/next_tick.js:63:19)
[nodemon] app crashed - waiting for file changes before starting...

node vault is not able to initialize and gives me the error Error: connect ECONNREFUSED 127.0.0.1:8200

The error is as shown below:
{ RequestError: Error: connect ECONNREFUSED 127.0.0.1:8200
at new RequestError (C:\Users\anand\quFlipApi\node_modules\request-promise\lib\errors.js:11:15)
at Request.RP$callback [as _callback] (C:\Users\anand\quFlipApi\node_modules\request-promise\lib\rp.js:60:32)
at self.callback (C:\Users\anand\quFlipApi\node_modules\request\request.js:188:22)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7)
at Request.onRequestError (C:\Users\anand\quFlipApi\node_modules\request\request.js:884:8)
at emitOne (events.js:96:13)
at ClientRequest.emit (events.js:188:7)
at Socket.socketErrorListener (_http_client.js:310:9)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at emitErrorNT (net.js:1276:8)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickDomainCallback (internal/process/next_tick.js:122:9)
name: 'RequestError',
message: 'Error: connect ECONNREFUSED 127.0.0.1:8200',
cause:
{ Error: connect ECONNREFUSED 127.0.0.1:8200
at Object.exports._errnoException (util.js:1026:11)
at exports._exceptionWithHostPort (util.js:1049:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1085:14)
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 8200 },
error:
{ Error: connect ECONNREFUSED 127.0.0.1:8200
at Object.exports._errnoException (util.js:1026:11)
at exports._exceptionWithHostPort (util.js:1049:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1085:14)
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 8200 },
options:
{ method: 'PUT',
path: '/sys/init',
json: { secret_shares: 1, secret_threshold: 1 },
headers: { 'X-Vault-Token': undefined },
uri: 'http://127.0.0.1:8200/v1/sys/init',
simple: false,
resolveWithFullResponse: true,
callback: undefined,
transform: undefined },
response: undefined }
Connection with database succeeded.
The code for that is as shown below:
app.js
var options = {
apiVersion: 'v1', // default
endpoint: 'http://127.0.0.1:8200' // 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);
I have already removed clienttoken field to avoid any complexity, but still it is giving me the error.In this above code should I enter /remove any other field to make it work ?

Resources