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...

3 comments:

  1. 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
    ```

    ReplyDelete
  2. 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?

    ReplyDelete
    Replies
    1. i post articles so as to help the greater amount of people online. all coffeescript people know javascript. posting as javascript is more accessible

      Delete