-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
27 lines (22 loc) · 695 Bytes
/
Copy pathindex.js
File metadata and controls
27 lines (22 loc) · 695 Bytes
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
var express = require("express");
var cors = require("cors");
var app = express();
const fetch = require("node-fetch");
const dotenv = require("dotenv");
dotenv.config();
app.use(cors());
app.get("/", function (req, res) {
const cityName = req.query.city; //to be replaced with post data
const apiKey = process.env.API_KEY;
const weatherUrl = `https://api.openweathermap.org/data/2.5/forecast/?q=${cityName},CA&appid=${apiKey}&units=metric`;
fetch(weatherUrl)
.then((res) => res.json())
.then((data) => {
console.log(cityName);
res.send(data);
})
.catch(console.log);
});
app.listen(3001, function () {
console.log("app listening on port 3001");
});