All you have to do is check the length of the keys in Object , e.g.
Object.keys(req.query).length
Sidenote: You mean inappropriate if-else behavior,
if (req.query !== {}) // this will run when your req.query is 'NOT EMPTY', ie it has some query string.
source share