Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

split() issues in node.js + express

split() issues in node.js + express

Problem

When I try to Split a string in node I get the following error...

TypeError: 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?

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.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

split() issues in node.js + express

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×