-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
28 lines (24 loc) · 881 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
25
26
27
28
const express = require("express");
const axios = require("axios");
const app = express();
app.listen(80);
app.get("/news", async (req, res) => {
axios
.get(
`https://newsapi.org/v2/top-headlines?country=ca&pageSize=10&apiKey=${process.env.NEWS_API_KEY}`
)
.then((result) => res.status(200).json(result.data))
.then(() => console.log("News Fetched"))
.catch((error) => res.status(500).json({ message: error.message }));
});
app.get("/weather", async (req, res) => {
axios
.get(
`https://api.openweathermap.org/data/2.5/onecall?lat=49.2472&lon=-123.1162&units=metric&exclude=${"hourly,minutely"}&appid=${
process.env.WEATHER_API_KEY
}`
)
.then((result) => res.status(200).json(result.data))
.then(() => console.log("Weather Fetched"))
.catch((error) => res.status(500).json({ message: error.message }));
});