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?
asked Jul 21 '12 at 6:45
68433 gold badges88 silver badges1414 bronze badges
2 Answers
2
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.
answered Jul 21 '12 at 6:59
12.7k44 gold badges2626 silver badges3333 bronze badges
0
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'
'IT' 카테고리의 다른 글
MultiByteToWideChar (0) | 2021.07.06 |
---|---|
Felix's Node.js Style Guide (0) | 2021.07.06 |
모던 웹을 위한 Node.js 프로그래밍 3판[1차] (0) | 2021.07.06 |
JSPベスト・プラクティス: タイム・スタンプの力 (0) | 2021.07.05 |
jQueryのhover()を活用したマウス操作まとめ! (0) | 2021.07.05 |
댓글