-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
29 lines (24 loc) · 726 Bytes
/
server.js
File metadata and controls
29 lines (24 loc) · 726 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
import express from 'express';
import 'dotenv/config';
const app = express();
const port = process.env.PORT || 3000;
app.use(express.static('public'));
app.use(express.json());
app.get('/', (req, res) => {
res.send('public')
})
app.post('/api/response', async(req, res) => {
let loc = req.body.loc;
let response = await fetch(`https://api.weatherapi.com/v1/current.json?key=${process.env.API_Key}&q=${loc}&aqi=no`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(loc)
});
let data = await response.json();
res.json(data);
})
app.listen(port, () => {
console.log('app listenening on http://localhost:3000')
})