I'm a neebie in JS and Node. I would like to display weather in a city with OpenWeatherMap. I've got this code :
var querystring = require('querystring');
var request = require("request");
var result = '';
var text = '';
var openWeatherMapQuery = querystring.stringify({
q: "Bourges, France",
lang: "fr",
units: "metric"
});
var openWeatherMapURL = "http://ift.tt/1mGUATE?"+ openWeatherMapQuery;
request({
url: openWeatherMapURL,
json: true // Nous recevrons un JSON
}, function (error, response, resp) {
if (!error && response.statusCode === 200) {
var text = "Bulletin météo : "
text += resp.weather[0].description
text += ". Il fait actuellement "+ Math.round(resp.main.temp) +" degrés."
var result = querystring.stringify({
tl: "fr",
q: text,
ie: "UTF-8"
});
console.log("Météo construite :");
console.log(text);
console.log(resp.main.temp);
} else {
console.log("Une erreur est survenue.");
}
})
module.exports.result = result;
module.exports.text = text;
This code works, but I can't display any result in my ejs page. Could someone help me please ?
Thanks a lot,
ANDRE Ani
Aucun commentaire:
Enregistrer un commentaire