Subburaj
Subburaj

Reputation: 5192

node.js query string count

In my node app i am getting the query string using "req.query.params,its working fine.But i want to know the no.of(count) of query string. Based on that i have to do switch case.

When i tried for: req.query.length and req.query.size it prints undefined .

My code:

app.get('/geocode', function (req, res) {
console.log("Inside 11111111=" + req.query.-------)
)};

Consider my url: http://xxx.xxx.xxx.xxx/geocode?level0=""&level1=""&level2""

I want to get the count as "3"

What i have replace ------ to get the count.

Help me to solve this.Thanks in advance..

Upvotes: 0

Views: 1646

Answers (2)

Subburaj
Subburaj

Reputation: 5192

At last i after a lots of google i found the way:

var queryObject = url.parse(req.url,true).query;
console.log(Object.keys(queryObject).length);

The above code does the magic..

Upvotes: 1

Dagan Bog-Computers
Dagan Bog-Computers

Reputation: 608

I whould recommened to console.log(req) and console.log(res). and see if there is the result wanted inside (I think it might be in req.body).

If you do get 3 on all the params that is given there. You found your answer

Upvotes: 0

Related Questions