I have a JS Array declared like this:
var phones = [
{name: "Redmi Note 5" , manufacturer: "Redmi" , price: 9999},
...
];
I listen to this server with the following code:
app.listen(9999, function (err) {
if (err) {
throw err
}
console.log('Server started on port 9999');
})
This is the function I'm utilizing:
app.get('/get-items' , function(req , res) {
var resu = phones;
var man = (req.query['manufacturer'] === '');
var mod = (req.query['name'] === '');
console.log(man);
console.log(mod);
if (man)
sortman(req , resu);
if (mod)
sortmod(req , resu);
var jsonResult = JSON.stringify(resu);
res.set('Content-Type', 'application/json');
res.send(jsonResult);
})
If I give a URL like http://localhost:9999/get-items?manufacturer=Samsung
, I get both the log as false, and even if I don't give any parameter, both the logs still show false.
I would like to know whether I am indeed supposed to use req.query['name']
or should I use something else?
EDIT: I have the required dependencies declared using require()