jquery - How to get JSON from a distant server in an express server? -


i'm looking way replicate jquery method getjson server side. server i'm using node.js server express framework written in coffeescript.

the code have client side :

# client ip $.getjson("http://jsonip.com?callback=?", (data) ->       # more information ip   $.getjson("http://freegeoip.net/json/" + data.ip, (fulldata) ->     console.log fulldata)) 

the fulldata variable give me information client ip.

i have avoid using javascript client side, try same server side, client ip doing :

(req, res) ->   # client ip   req.ip 

but after that, have no idea how fulldata in json freegeoip.net server.

help, ?

i used skelly solution.

so did :

request = require 'request'  (...)  (req, res) ->   url = 'http://freegeoip.net/json/' + req.ip   request.get(url, (error, response, body) ->     if !error        console.log body   ) 

the body contains data need.

i'm sure david fregoli's native node.js solution works also, request package works , easily.

thanks them both.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -