-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
24 lines (20 loc) · 859 Bytes
/
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
const express = require("express");
const fetch = require("node-fetch");
const { response } = require("express");
const { request } = require("http");
const app = express();
require("dotenv").config();
app.use(express.static(__dirname + "/public"));
app.use(express.static(__dirname + "/client"));
app.get("/weather/:latlong", async (req, res) => {
const api_key = process.env.API_KEY;
const latlong = req.params.latlong.split(",");
const lat = latlong[0];
const long = latlong[1];
const api_url = `http://api.openweathermap.org/data/2.5/onecall?lat=${lat}&lon=${long}&units=imperial&appid=${api_key}`;
const fetch_response = await fetch(api_url);
const json = await fetch_response.json();
res.json(json);
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => console.log(`server running on ${PORT}`));