Search code examples
node.jsexpressyahoo-api

call yahoo weather api with nodejs


I want achieve following functionality.

when browser hits localhost:3000/weather server goes to router defined with "weather" mount path.

In order to get data from yahoo weather api should I call it in that route with superagent or proxy is needed for this?


Solution

  • Learn more about requeston npm.

    First do

    npm install request
    

    then, in your routes files, say index.js

    router.get('/weather', function(req, res, next){
        request('http://www.yahoo.com/your/api/url', function (error, response, body) {
            if (!error && response.statusCode == 200) {
                console.log(body);
                res.send(body); // this will send data to client.
            }
        })
    });