split() issues in node.js + express
Problem
When I try to Split a string in node I get the following error...
TypeError: Object #
Here is the split code I am using...
var query = req.query;
query.split(",");
I am using express to create my server, it seems like it is looking for a module, but isn't .split() a standard method with node.js?
Problem courtesy of: Collin McGuire
Solution
req.query
simply isn't a string; it's an object, created by parsing the query string in req.url
into key-value pairs. Therefore it doesn't have a split
method, since that's only for strings. If you need the literal text of the query string (like because it's not actually made up of key-value pairs), use url.parse(req.url).query
.
Solution courtesy of: ebohlman
Discussion
View additional discussion.