Node.js/ejs - How to see if req.body contains a get request without equals

I have code which redirects to ?success, but even if it is there or not console.log(req.body.success) always returns undefined, so how can I tell if it is there if it doesn’t have an equals sign?

@Anish helped me out in a DM
Here’s the code if you need it:

var success = false
var url = req.url.split('?')
if (url[1] == "success"){
 success = true
} 
1 Like

here’s better solution:

const isSuccess = !!req.query.success

You can trick your first solution by going to address.com/?success=true. You will get url[1] as success=true

The first one is fine as I am just redirecting to ?success not ?success=true (no user input required) but we’ll leave it here in case I (or someone else) needs it for something else, where user input is required :slight_smile:
Eddie