Priya
Priya

Reputation: 1481

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?

Upvotes: 0

Views: 1260

Answers (1)

AdityaParab
AdityaParab

Reputation: 7100

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.
        }
    })
});

Upvotes: 1

Related Questions