I'm making a GET endpoint that handles this variable in Node.js using Express:
?message-timestamp=2012-08-19+20%3A38%3A23
I'm having trouble accessing it using req.query. Accessing req.query.message-timestamp throws an error ("ReferenceError: timestamp is not defined"). Clearly the dash isn't playing nice.
Any obvious way around that?
In javascript, object values can be accessed by using either .
or []
When the key contains a dash, you cannot use the .
notation because the -
will be interpreted as "minus". This is not related to express
, it's just how javascript works.
So you should use:
req.query["message-timestamp"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With