-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
44 lines (31 loc) · 1.29 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const express = require("express");
const https = require("https");
const bodyparser = require("body-parser")
const app = express();
app.use(bodyparser.urlencoded({extended: true}));
app.get("/", function(req, res){
res.sendFile(__dirname + "/index.html");
});
app.post("/", function(req, res){
const query = req.body.cityname;
const apikey = "enter your api key"//go toany api weather app u will get an api
const unit = "metric"
const url = "https://api.openweathermap.org/data/2.5/weather?q=" + query + "&appid=" + apikey + "&units=" + unit;
https.get(url, function(response){
console.log(response.statusCode);
response.on("data", function(data){
const weatherdata=JSON.parse(data)
const temp = weatherdata.main.temp
const weather = weatherdata.weather[0].description
const icon = weatherdata.weather[0].icon
const imageURL = "http://openweathermap.org/img/wn/" + icon +"@2x.png"
res.write("<p>The weather in " + query +" is " + weather + "</p>")
res.write("<h1>The temperature in <I>" + query +"</I> is " + temp + " in degree celcius</h1>");
res.write("<img src=" + imageURL +">");
res.send()
})
})
})
app.listen(process.env.PORT || 3000,function(){
console.log("server is running on port number 3000");
})