I’m creating a text-to-speech service with the help of IBM Watson API. Using the following code segment I was able to download the converted .wav file to my server. But I do not want to store audio files whenever a text has been converted. How can I send the buffer directly to the users to download? Ans…
Tag: express
How can I check if an EJS variable exists?
I used EJS layout in my Node.js application. Currently I faced a problem when data which is required in the EJS file is not available then it simply generate an error. What I want is to add a condition before using the EJS variable in javascript. Here is my code in which I use EJS variable inside script tag. …
Node.js throws TypeError: Cannot destructure property ‘firstName’ of ‘req.body’ as it is undefined, even though it works for an other post request
So I know there are tons of similar questions out there, and I’ve read most of them in the past few days. However I didn’t find any solution to my problem. The app is about users can post memories(cards) etc… Point is, when I create a new card with POST request, there is no problem, but when…
Is it possible to convert a buffer to base64string in populate mongoose?
I have a mongoose Image Schema as below: and a Chapter schema I’ll do population for the image and I’m trying to convert the buffer to base64string for every single image in the chapter. Could anyone please help me? is there a way to do conversion on populate function in mongoose? or I have to map…
session value is not stored properly
I am using express-session and express-mysql-session in my app to generate sessions and store them in mysql database. Sessions are stored in a table called sessions. Sessions are stored in table but the value of it is not as same as the session value in client-side or console. Example: decoded value in client…
How to Mongoose send different value on find of specific field
I have a field which contain url to an image which is protected. It needs a secret to access file and the secret expire after a time. I want that when I do Mode.find() then the url value get replaced by anther url which contains the secret. So, that I don’t have to manually every where I find from the
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…
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…
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…
Unit testing a method that creates a JWT and returns Error: secretOrPrivateKey must have a value
I am trying to write a unit test for the method I wrote which generates a JWT. I am doing the following Note: I am not using expect yet, and seeing if the method works in first place by logging the result of the method to the console And I receive the following error: Error: secretOrPrivateKey must have a val…