This should work properly as the coide is correct.
the output should be – json on my browser window when the write the adress and load.
But i am seeing Searching for undefined written on my browser window.
And in the console
Server running on port 3000
Body:
{}
Query:
undefined
What the heck!!! I never implemented this. MY output is json always even if it fails in code.
- Bckend code part
// app is express()
app.get('/search/',
query('q').trim().notEmpty(),
(req, res)=>{
const queryParam = req.query.q;
console.log(`Query parameter: ${queryParam}`);
const errors = validationResult(req);
if(!errors.isEmpty()){
return res.send(errors);
}
const data = matchedData(req);
res.send(data);
}
);
- browser adress bar adress i used
http://localhost:3000/search/?q=abc
I tried changing the word ‘search’. We can use anything there inplace of search where i used it. even searc – just removing a h – gives us desired result.
So the problem is in the word search as route.!!!
Why so? PLease explain.
Its killing me inside as it should not a problem by any chance.
2