Doubt in arnav bhaiya's code in LVWD-12

const express = require(“express”)

const app = express()

app.use("/" , express.static(__dirname + “/public”))

function decodeQuerybase64 (req,res,next) {
console.log(req.query)
console.log(typeof req.query)
for(let q in req.query){
let data = req.query[q]
data = new Buffer.from(data,‘base64’).toString(‘ascii’)
req.query[q]=data

}
    
next()

}

app.get("/eval", decodeQuerybase64 ,(req,res) => {
console.log(req.query)
res.send("========================eval request==================")
})

app.listen(3333 , () => {
console.log(“server Started in http://localhost:3333”)
})

DOUBT:- I dint understand what arnav bhaiya did in decodeQuerybase64 function. Like why we are making a for loop and what does that Buffer means and does

Buffer is a storage container which just stores some data so that a consumer can consume it at its own speed. Better explanation: https://stackoverflow.com/questions/648309/what-does-it-mean-by-buffer

Here, decodeQuerybase64 just decodes all the data in req.query object, which is base64 data into normal ascii data so that furthur middlewares (like /eval) can use it.

base64 and asciii are data representation formats.
Read these:


anirudh bhaiya , I understood the base64 encoding thing. I just want to know why are we using a for loop in decodeQuerybase64 function. What does "req.query[q] "means?

See this https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.