a mash-up of interests and activities, including web development, music, design, and pittsburgh life
Monday, March 19, 2012
node.js http request example
A http server acting as a google reverse geocoder API proxy.
You just need to pass in long/lat as querystrings, for example, "localhost/?hi=there&long=37&lat=37". I put the hi=there in there because node querystring module parses strangely...
The reason why it's "parsing strangely" is that req.url is not a querystring, but the full url path. Also, you're parsing it more than once, which is a bit unnecessary (though probably harmless).
Try this:
``` var url = require('url')
// ... in the server var u = url.parse(req.url, true) // now, use u.query.lat, u.query.long ```
The reason why it's "parsing strangely" is that req.url is not a querystring, but the full url path. Also, you're parsing it more than once, which is a bit unnecessary (though probably harmless).
ReplyDeleteTry this:
```
var url = require('url')
// ... in the server
var u = url.parse(req.url, true)
// now, use u.query.lat, u.query.long
```
why don't you use coffeescript? You're going so far to make an array look decent with commas at the beginning, why put commas in at all?
ReplyDeletei post articles so as to help the greater amount of people online. all coffeescript people know javascript. posting as javascript is more accessible
DeleteAppreciiate you blogging this
ReplyDelete