Here is my code… When I’m trying to access schedule.passenger inside the async function It’s working but when trying to access outside the async function it’s not working. Answer forEach(async function will fire bunch of async functions and once array iterations are complete, the execu…
Tag: node.js
Discord.js ‘presenceUpdate’ not being called
I have a “Special User” which is equal to ‘Client.users.fetch(Special User’s ID)’. Then the user has two event listeners attached to the it, ‘message’ and ‘presenceUpdate’, The message event listener works perfects, although the presenceUpdate does not wor…
import JSON file with node.js
I want data from the config.json file import to the index.js file in the same dir. so I had it before now i would change the string so i need a json object, but how? Answer In ES5 you can do it by The object will contain your JSON. In ES6 Using fs module synchronously
How to click and hold in Puppeteer
I am trying to click and hold using Puppeteer. I tried using page.click inside a while loop but it didn’t work. I also tried this: Any ideas how to do this? Answer There are a few tools to trigger a mouse hold in Puppeteer: page.click, mouse.click, mouse.down and mouse.up. page.hover can be useful for p…
How to listen to keyboard events in electron without interrupting default behavior?
I was trying to listen to Ctrl-C event using electron globalShortcut module, but as it seems, electron is re-writing default behavior automatically (without features like preventDefault in plain javascript). Here’s what I did: Is there an another way to listen to global keyboard shortcut events using el…
What’s the best way to re-run a const-declared function?
New to ES6 here. I have a function declared “inside” a constant: I need to re-run this periodically. What’s the best way to do it? Simply calling requestData() is throwing ‘Type Error’ messages. Thanks! Answer The second argument to https.request is a function reference that is c…
Cannot find error while destructuring arguments in TypeScript
I’m porting some code to TypeScript, and a bit stumped by this error. The SomeObject type is supposed to allow an object with any named keys which equate to string values. When using in unpacked argument fields, I get two errors: ‘SomeObject’ is declared but its value is never read. and Cann…
Why is the client not receiving the socket.io broadcast (rooms)?
My client is not receiving the broadcast sent to the room. If I replace socket.to(roomName).emit(‘join’, currentUser); with socket.emit(‘join’, currentUser); the client receives the broadcast, but I’d like to use rooms here. Any help would be greatly appreciated. app.js game.ejs …
Trying to retrieve information from a db [node js, mysql, promise]
This is supposed to be a simple connection to access a localhost database. Important information: I’ve tried very similar code, if not the exact same, and it works. The difference is I didn’t put the connection in a class variable (this.connection) but because it’s not async I didn’t t…
How to turn data from a txt file into an array of objects in Node
I’m new to Node, and I have a text file that has data like this I would like to create an array of objects like this How can I do this? This was my attempt: But this create an array for each object and I get all the data showing under date like this: Answer You can try readline internal