Is hosting a discord.js bot. The bot's function is using fs.watchFile and fs.readFile to monitoring changes in a text files and send Discord embed that summarises the data entries within a target.txt file. However, the bot always crash after running for a few hours and throwing process.nextTick error:
C:\Users\Administrator\Desktop\Bot\node_modules\ws\lib\websocket.js:1035
process.nextTick(resume, websocket._socket);
TypeError: process.nextTick is not a function
at Receiver.receiverOnConclude (C:\Users\Administrator\Desktop\Bot\node_modules\ws\lib\websocket.js:1035:11)
at Receiver.emit (node:events:526:28)
at Receiver.controlMessage (C:\Users\Administrator\Desktop\Bot\node_modules\ws\lib\receiver.js:576:14)
at Receiver.getData (C:\Users\Administrator\Desktop\Bot\node_modules\ws\lib\receiver.js:423:42)
at Receiver.startLoop (C:\Users\Administrator\Desktop\Bot\node_modules\ws\lib\receiver.js:148:22)
at Receiver._write (C:\Users\Administrator\Desktop\Bot\node_modules\ws\lib\receiver.js:83:10)
at writeOrBuffer (node:internal/streams/writable:389:12)
at _write (node:internal/streams/writable:330:10)
at Receiver.Writable.write (node:internal/streams/writable:334:10)
at TLSSocket.socketOnData (C:\Users\Administrator\Desktop\Bot\node_modules\ws\lib\websocket.js:1187:35)
All these code is working except getting the process.nextTick's TypeError every few hours, unsure which part caused the error...or can the error be bypass by monkey patching?
Did not find a way to fix the discord.js script from getting that process.nextTick error but pm2 npm package can at least prevent script from stopping.
https://pm2.keymetrics.io/
How to use pm2 to autorestart my discord bot
I'm trying to integrate google maps into my react native app I keep getting this error.
events.js:183
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE :::8081
at Server.setupListenHandle [as _listen2] (net.js:1360:14)
at listenInCluster (net.js:1401:12)
at Server.listen (net.js:1485:7)
at C:\projects\test\node_modules\metro\src\index.js:205:18
at new Promise (<anonymous>)
at Object.<anonymous> (C:\projects\test\node_modules\metro\src\index.js:204:12)
at Generator.next (<anonymous>)
at step (C:\projects\testnode_modules\metro\src\index.js:58:30)
at C:\projects\test\node_modules\metro\src\index.js:69:15
at <anonymous>
Assuming you are using Linux.
It seems that your process is locked. In a terminal type the following:
ps -aux | grep '8081
copy the process ID
type in the terminal
sudo kill -9 ID-HERE replace ID-HERE with the process ID.
Restart the application.
If you are using Windows
type Ctrl+SHIFT+Esc to open the process window
Look for your process
Right click on the process and choose end process
Restart the application
I tried to run the following command:
node index.js
However, I get the following from my terminal:
success connection to port 3000
(node:16767) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkError
: connect ECONNREFUSED 127.0.0.1:27017]
at Pool.<anonymous> (/Users/hatchery/Documents/nodejs/fxexpress/node_modules/mongoose/node_modules/mongodb-core/lib/topologies/server.js:503:11
)
at emitOne (events.js:116:13)
at Pool.emit (events.js:211:7)
at Connection.<anonymous> (/Users/hatchery/Documents/nodejs/fxexpress/node_modules/mongoose/node_modules/mongodb-core/lib/connection/pool.js:326:12)
at Object.onceWrapper (events.js:317:30)
at emitTwo (events.js:126:13)
at Connection.emit (events.js:214:7)
at Socket.<anonymous> (/Users/hatchery/Documents/nodejs/fxexpress/node_modules/mongoose/node_modules/mongodb-core/lib/connection/connection.js:245:50)
at Object.onceWrapper (events.js:315:30)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211: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)
(node:16767) 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:16767) [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.
I am not sure why I am getting this error. Could anyone advice what to do?
If you are using mongoDB.Atlas go to network access and set Whitelist Entry: 0.0.0.0/0.
Re-run your command.
While the above solution might work, it is better to understand on how to debug and what the error says.
You got UnhandledPromiseRejectionWarning, because in your code, you must not be handling the promise rejection case where you are connection to MongoDB.
Next, the node server failed to connect to the mongodb. This could be because of several reasons. One simple case as mentioned by #Sayegh, the server itself is not running. Could be other reason like wrong port etc, server not accepting incoming connections etc.
How to debug. First step is to figure out if the process is running or not. One simple way would be to run this command ps aux | grep mongo which list all processes from all users with mongo as a text.
If this was true and still unable to connect, look for port. If still unable to connect, check if the server accepts incoming connection and take it from there.
Not sure what system you're on, but try running this if you're on Linux:
mongo
or for macOS:
mongod
and leave it running in a new terminal and then try running the server again
Before you launch your NodeJS command, make sure to create the right directories with the right permissions:
> sudo mkdir -p /data/db
> sudo chmod -R go+w /data/db
I had the same issue and solved by changing the database user's username and password to something much more simple like dev:dev and I had an error using it with user-dev:user-dev ... just change it to something simple
First I tried Skitty's solution, and it didn't work for me, but I still keep the solution in my code, and then I changed app.listen(process.env.PORT || 3000); and it worked for me.
I faced same issue but after a lot of RND. I found that whts the problem so run this command on your terminal.
sudo service mongod start
then run mongo on terminal and look.
Just repair the mongodb installed in your system. By clicking on the package you installed you will have an option to repair it.
If you are using Mongo db atlas go on Network access and set to your current IP address and then re-run your command.
I hope it will work for you.
MongoDB connection expects you to put URL encoded password. But when I had a password with '.' (xxx.xxx), the url encoding of that remains as dot. However, it still did not work.
i changed the password to simple all lower case string and it worked fine.
Not sure why it is not accepting. But this solved the issue for time-being.
If you are a Mac user, this might be a relevant comment. For me it was because server was not running. On running mongodb, I saw in console a message saying there is no /data/db and / is not writable for me. So I used synthetic.conf solution.
sudo mkdir -p /System/Volumes/Data/data/db
sudo chown -R whoami /System/Volumes/Data/data/db`
echo "data\t/System/Volumes/Data/data" | sudo tee -a /etc/synthetic.conf
reboot your system
run mongodb
and it works.
I know this has been raised a lot of times on here, other threads suggest that the port is already in use and that's why it crashes.
In this case, it's been running for days, using that port and will randomly crash with this error. It's had the port locked for days with no problems and is literally the only daemon on the server.
We're running on port 3000.
events.js:72
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ESRCH
at errnoException (dns.js:37:11)
at Object.onanswer [as oncomplete] (dns.js:124:16)
Any help would be grateful
I am getting the following error when I try to run sails lift on my project:
clayton#cfs846631:~/Documents/stream-sync$ sails lift
[Error: failed to connect to [localhost:27017]]
/home/clayton/Documents/stream-sync/node_modules/sails-mongo/lib/adapter.js:77
connection.createCollection(collectionName, function __DEFINE__(err, r
^
TypeError: Cannot call method 'createCollection' of undefined
at __DEFINE__ (/home/clayton/Documents/stream-sync/node_modules/sails mongo/lib/adapter.js:77:20)
at afterwards (/home/clayton/Documents/stream-sync/node_modules/sails-mongo/lib/adapter.js:469:7)
at /home/clayton/Documents/stream-sync/node_modules/sails-mongo/lib/adapter.js:465:7
at /home/clayton/Documents/stream-sync/node_modules/sails-mongo/lib/adapter.js:500:23
at /home/clayton/Documents/stream-sync/node_modules/mongodb/lib/mongodb/db.js:273:18
at /home/clayton/Documents/stream-sync/node_modules/mongodb/lib/mongodb/db.js:351:18
at Server.close (/home/clayton/Documents/stream-sync/node_modules/mongodb/lib/mongodb/connection/server.js:210:38)
at Db.close (/home/clayton/Documents/stream-sync/node_modules/mongodb/lib/mongodb/db.js:347:21)
at /home/clayton/Documents/stream-sync/node_modules/mongodb/lib/mongodb/db.js:271:21
at null.<anonymous> (/home/clayton/Documents/stream-sync/node_modules/mongodb/lib/mongodb/connection/server.js:563:7)
at EventEmitter.emit (events.js:106:17)
at null.<anonymous> (/home/clayton/Documents/stream-sync/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:140:15)
at EventEmitter.emit (events.js:98:17)
at Socket.<anonymous> (/home/clayton/Documents/stream-sync/node_modules/mongodb/lib/mongodb/connection/connection.js:512:10)
at Socket.EventEmitter.emit (events.js:95:17)
at net.js:440:14
at process._tickDomainCallback (node.js:459:13)
I have attempted to reinstall sails, and also saw that it might be related to the adapters.js file in config. I updated the mongo adapter to use host: 'localhost'. This project is working fine on my laptop, I am just trying to get it set up on my desktop now, so I am assuming it has something to do with the way sails is set up or missing node modules.
I don't know what else to try at this point.
You get this error because sails cannot connect to your mongodb server.
[Error: failed to connect to [localhost:27017]]
install/start mongodb and sails will lift correctly. If you have trouble to get mongodb running try the official docs http://docs.mongodb.org/manual/installation/