When I try to split a string in node I get the following error...
TypeError: Object #<Object> has no method 'split'
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?
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
.
req.query
is not a string, it's an object representing the query string:
// url: /something?id=1&key=value
req.query.id == 1
req.query.key == 'value'