DiscordJS and Linux's Screen - node.js

I'm facing an issue with discordjs and i don't understand it. I run "node main.js" into a linux screen, detach it, go to sleep and when i come back, it crashed. Could you enlight me ?
# screen -r BotApex
(node:6559) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
events.js:180
throw err; // Unhandled 'error' event
^
Error [ERR_UNHANDLED_ERROR]: Unhandled error. ([object Object])
at Client.emit (events.js:178:17)
at WebSocketConnection.onError (/root/ApexLegendsSnipeBot/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:374:17)
at WebSocket.onError (/root/ApexLegendsSnipeBot/node_modules/ws/lib/event-target.js:128:16)
at WebSocket.emit (events.js:189:13)
at _receiver.cleanup (/root/ApexLegendsSnipeBot/node_modules/ws/lib/websocket.js:211:14)
at Receiver.cleanup (/root/ApexLegendsSnipeBot/node_modules/ws/lib/receiver.js:557:13)
at WebSocket.finalize (/root/ApexLegendsSnipeBot/node_modules/ws/lib/websocket.js:206:20)
at TLSSocket.emit (events.js:189:13)
at emitErrorNT (internal/streams/destroy.js:82:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)

Looks like your bot ran into an error event while you were away. If you don't handle error events they usually make your bot crash. To prevent the bot from crashing, simply add an error listener:
client.on("error", info => {
console.log('Error event:\n' + JSON.stringify(info));
// handle the error here
});
Please keep in mind that the error event has been called for some reason and that you should handle the error afterwards.

Related

Failed to connect to MongoDB ( remote server )

I am trying to deploy an Angular/NodeJS app on the server I just bought.
( http://o2switch.fr is the provider )
I managed to deploy the angular part, but I have trouble with the connexion to mongoDB
When I launch app.js in my terminal, it says :
(node:30382) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [cluster0-shard-00-00.cgjma.mongodb.net:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 15.237.158.132:27017]
at Pool.<anonymous> (/home/ewhc6963/nodevenv/node/10/lib/node_modules/mongoose/node_modules/mongodb/lib/core/topologies/server.js:441:11)
at Pool.emit (events.js:198:13)
at createConnection (/home/ewhc6963/nodevenv/node/10/lib/node_modules/mongoose/node_modules/mongodb/lib/core/connection/pool.js:564:14)
at connect (/home/ewhc6963/nodevenv/node/10/lib/node_modules/mongoose/node_modules/mongodb/lib/core/connection/pool.js:1014:9)
at makeConnection (/home/ewhc6963/nodevenv/node/10/lib/node_modules/mongoose/node_modules/mongodb/lib/core/connection/connect.js:32:7)
at callback (/home/ewhc6963/nodevenv/node/10/lib/node_modules/mongoose/node_modules/mongodb/lib/core/connection/connect.js:300:5)
at TLSSocket.err (/home/ewhc6963/nodevenv/node/10/lib/node_modules/mongoose/node_modules/mongodb/lib/core/connection/connect.js:330:7)
at Object.onceWrapper (events.js:286:20)
at TLSSocket.emit (events.js:198:13)
at emitErrorNT (internal/streams/destroy.js:91:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
at process._tickCallback (internal/process/next_tick.js:63:19)
(node:30382) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:30382) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Basically, it doesn't manage to connect to MongoDB even though in localhost, it works fine.
app.js :
mongoose.connect(config.DB_URI, function(err, db){
if (err) throw err;
console.log('Connected to database');
}, { useNewUrlParser: true });
config/server.js :
module.exports = {
DB_URI : 'mongodb+srv://pseudo:password#cluster0.cgjma.mongodb.net/rank'
}
Mongo connection fails. So you should handle the promise rejection. You may use .catch() method to do that. You can check this link.

node:events:371 throw er; // Unhandled 'error' event ^ Error: read EFAULT

I've been getting this error and have tried reinstalling node/vscode already to no avail. This happens maybe 30% of the time after I save my changes in vscode and it ALWAYS crashes my node server.
Nodemon doesn't turn my server back on and it gets really tedious when trying to code. Does anyone have any solutions to this problem?
I'm running on a Macbook Air 2020 with a M1 chip if that makes a difference.
(Using express / nodejs ) node v16.6.0
I've tried killall node, I've tried changing port number. same errors
throw er; // Unhandled 'error' event
^
Error: read EFAULT
at Pipe.onStreamRead (node:internal/stream_base_commons:211:20)
Emitted 'error' event on Socket instance at:
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: -14,
code: 'EFAULT',
syscall: 'read'
}```

Unhandled 'error' event how to find out which line of code it's happening?

I'm getting this error:
events.js:137
throw er; // Unhandled 'error' event
^
Error: socket hang up
at createHangUpError (_http_client.js:330:15)
at Socket.socketOnEnd (_http_client.js:423:23)
at Socket.emit (events.js:165:20)
at endReadableNT (_stream_readable.js:1101:12)
at process._tickCallback (internal/process/next_tick.js:152:19)
I know it's a socket.on('error') not handled, but the problem is I don't know where this socket is in my code. It doesn't say the line. Also this error only happens every 10min or so so I can't just comment things in and out and retry. Where can I know the exact line this socket is at?

Node.js server not working all of a sudden

It worked fine yesterday and now it's giving me this error. The API I created worked fine and all of the requests worked, now I have no idea what's wrong.
I used ng serve for my Angular app and node app.js for my API server and everything worked fine, why isn't it connecting now?
Running on port 4000...
(node:13096) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
(node:13096) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkError: connection 0 to localhost:27017 timed out]
at Pool.<anonymous> (C:\Users\Heiko\Documents\parkingApi\node_modules\mongodb-core\lib\topologies\server.js:564:11)
at Pool.emit (events.js:182:13)
at Connection.<anonymous> (C:\Users\Heiko\Documents\parkingApi\node_modules\mongodb-core\lib\connection\pool.js:317:12)
at Object.onceWrapper (events.js:273:13)
at Connection.emit (events.js:182:13)
at Socket.<anonymous> (C:\Users\Heiko\Documents\parkingApi\node_modules\mongodb-core\lib\connection\connection.js:257:10)
at Object.onceWrapper (events.js:273:13)
at Socket.emit (events.js:182:13)
at Socket._onTimeout (net.js:448:8)
at ontimeout (timers.js:424:11)
at tryOnTimeout (timers.js:288:5)
at listOnTimeout (timers.js:251:5)
at Timer.processTimers (timers.js:211:10)
(node:13096) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:13096) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
The log clearly shows that your node server is unable to connect to MongoDB. The reasons might be any. Let me list down a few possibilities.
MongoDB Server is down. You might have to restart the same
You node server might be behind some firewall which doesn't allow DB connection to external DBs.
You can check the connection from shell using:
mongod "mongodb_host_url"

I was trying to build a API with node.js, express and mongodb. After installing nodemon mongodb went wrong

It seems like the mongodb server connection went wrong but I was not able to figure out how to fix the problem. Can someone went through the same issue please help me out? Thank you so much!
Error messages in terminal are as follows:
(node:63820) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017]
at Pool.<anonymous> (/Users/Harry/Documents/code/testAPI/node_modules/mongodb-core/lib/topologies/server.js:503:11)
at Pool.emit (events.js:127:13)
at Connection.<anonymous> (/Users/Harry/Documents/code/testAPI/node_modules/mongodb-core/lib/connection/pool.js:326:12)
at Object.onceWrapper (events.js:219:13)
at Connection.emit (events.js:127:13)
at Socket.<anonymous> (/Users/Harry/Documents/code/testAPI/node_modules/mongodb-core/lib/connection/connection.js:245:50)
at Object.onceWrapper (events.js:219:13)
at Socket.emit (events.js:127:13)
at emitErrorNT (internal/streams/destroy.js:64:8)
at process._tickCallback (internal/process/next_tick.js:152:19)
(node:63820) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:63820) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
It seems there's no database instance running at localhost:27017. Be sure to start mongodb instance before running your code.
Depending on your OS, the process of starting mongodb daemon very, see https://docs.mongodb.com/manual/tutorial/manage-mongodb-processes/

Resources