-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
29 lines (22 loc) · 814 Bytes
/
Copy pathserver.js
File metadata and controls
29 lines (22 loc) · 814 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
28
29
require("dotenv").config();
const express = require("express");
const axios = require("axios");
const cors = require("cors");
const app = express();
const KEY = process.env.KEY;
app.use(cors());
app.get('/', (req, res) => {
const url = ` http://api.weatherbit.io/v2.0/forecast/daily?key=${KEY}&days=8&units=I&lat=${req.query.q[0]}&lon=${req.query.q[1]}`
axios.get(url)
.then(response => response.data)
.then(data => res.send(data))
.catch(err => console.log(err))
});
app.get('/search', (req, res) => {
const url = ` http://api.weatherbit.io/v2.0/forecast/daily?key=${KEY}&days=8&units=I&city=${req.query.q}`
axios.get(url)
.then(response => response.data)
.then(data => res.send(data))
.catch(err => console.log(err))
});
app.listen(3001, console.log("server listening on port 3001"));