Skip to content

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…

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…

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…