Raj
Raj

Reputation: 837

how to check if a parameter is present in the querystring in node.js

How to validate if a parameter is exits in the querystring or not in the node.js ?

I am validating like this

if(prm1 == null)
return error

But actually in the console.log(prm1) says undefined..

How to validate this exactly ?

Upvotes: 1

Views: 20434

Answers (1)

throrin19
throrin19

Reputation: 18197

If the parameter is not present in your queryString it is returned as undefined. The parameter wouldn't return null because it wasn't initialised.

try this :

if(typeof prm1 != 'undefined')
    return "error";

Upvotes: 6

Related Questions