So, I’m using Node, but all that’s printed on the screen is my database in JSON format and not index.html. This doesn’t occur when I use localhost, so I have no idea why it does show my index page. Can anyone help me? My code: Answer I didn’t exactly understand your question properly b…
Tag: node.js
What’s ExtendedMessage on discord.js
I’m on v12 and after a lot of time I decided to start coding again but I ran into a problem I can’t quite fix. At start I wanted to add a function to the Message class like so But after a while I saw that some messages I sent did not have this function and threw me an error
Send http request multiple times in node.js
I’m trying to send the same http request multiple times. I just put the request in a loop, but when I run the code it shows the response 1 time. Answer You should put the request inside the for loop:
Promise JavaScript Returning Empty Array
createFolder() function is returning an empty array. I am not sure what I am doing wrong but it needs to return the items within project_array Answer This is a classic, what you are doing is resolving the promise with the empty array before your node fs async methods have resolved. Try this instead: In essenc…
How to check if string matches any of the strings in the database
I’m trying to check if string matches any of the strings saved in database, but with the code I have right now it checks only the first one My code: Answer You should not return if the key does not match as you want to continue comparing keys. Something like:
JavaScript, What have I done wrong? [closed]
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers. Closed 1 y…
How to log return value after async/await?
Below have I pasted in PoC code, where I have removed lots of lines, but it shows the problem/question I am facing. createPost() returns a “post number” in the ret variable. I don’t need the “post number for anything else than logging it. With the current implementation, I have to defi…
Unable to run JEST test
I’m facing an issue when I try to import something using require() function in jest test file. script2.test.js Package.json babel.config.cjs I’m getting following errors when I run the test using npm test I’m new to JEST, any help is much appreciated. My Node version is 14.17.3 Thanks you. A…
Why doesn’t .then() need the async keyword when used (similar to await)? How does Javascript know it’s an asynchronous operation?
I’m starting to learn asynchronous Javascript and I’m really confused. To be honest, the async/await approach seems very logical to me. We need to let the runtime know we’re doing an asynchronous operation so it can handle it accordingly. But why don’t we need to do the same when using…
Cloudinary configuration is not read data from .env file
I’m using Cloudinary with my node.js project… The issue is cloudinary.config is not reading data from .env file, I have to type them directly! I’ll be thankful if anyone can help 🙏🏻 Answer Issue is solved with adding require(“dotenv”).config(); to the beginning of the same file w…