How can I find user with first letter in their name like for example my name is “Nathan” and when I type “n” in search input it will show user start with an “n” but not user that not start with letter “n” but contain letter “n” like Henry, Connor.. h…
Tag: node.js
How do I make a reaction log?
I wan’t to make a reaction log for my server, but I keep getting undefined. Here’s the code: Answer You need to get the property channel from messageReaction.message Documentation on MessageReactionAdd
Pass req,res from index.js to another js file in Node
[I am using express for node]. I encountered a code where the form-data is being posted into index.js but it has to be processed in another javascript file. I debugged the original code at nearly every step but at this point I am stuck. Here are the relevant parts in the files. index.js proctor.js (not writte…
SendGrid client TypeScript Error: HttpMethod
I have: But my TypeScript language server gives me an error about sendgridRequest: Is there some way to resolve this? Answer method: ‘PUT’ in your object is being inferred as string, but it’s expecting specific strings like “PUT” | “GET” | “POST”. This bec…
Why do I get an Unhandled Promise Rejection with await Promise.all
This is the general structure of my code: I expect this to catch any rejections happening in asyncActions because they should be handled by Promise.all(), but somehow they are unhandled? The console shows the following: Why are they not handled by Promise.all() and then caught in the catch block? I also notic…
Fastify: Ommit some APIs from using basic authentication
Currently, I have two APIs: /auth and /no-auth. I would like ONLY one of them to use basic-auth. I am using fastify-basic-auth plugin on top of fastify in node. /auth should require authentication. /no-auth should NOT require authentication. Currently, the way my code is set up, BOTH are requiring authenticat…
NodeJS middleware calling order
Why res.send(“main page 2”) not overriding res.send(“main page 1”) when I request localhost:3000 ? While execucing this code in NodeJS only console.log(“midddleware”) is calling from app.use method but not res.send. I wonder why it works like that. Answer You are likely bei…
Random picture of cats discord.js Uncaught TypeError: Cannot read property ‘pipe’ of undefined
I am trying to make a bot that sends cat pictures from a cat API but when I run the code it gives an error that I have never seen. When I run the code it returns Uncaught TypeError: Cannot read property ‘pipe’ of undefined. Answer Instead of the low-level xmlhttprequest you could use node-fetch to…
Display data after user input form (mysql-nodejs)
I have a page where there is a form, in which user will fill inputs. Then, I redirect to another page in which depending on the user’s choices some data will be displayed (the data will come from a mysql database). This is my code: index.js (here are my routes) airTicketsController.js (a controller wher…
Generate unique combinations in JavaScript from n objects with r samples
What is the best way to generate all unique combinations in JavaScript from N objects with R samples. For example: Expected result I am able to achieve above using recursive solution. But it is slow for large datasets (e.g. N=25, R=10). Is there any faster way to achieve this? Answer Ok, here a straight imple…