forked from bsack23/Assignment5
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex,js
More file actions
41 lines (19 loc) · 708 Bytes
/
index,js
File metadata and controls
41 lines (19 loc) · 708 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
30
31
32
33
34
35
36
37
38
39
40
41
// import express from 'express';
const express = require('express');
// declare and initialize the express server
const app = express();
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(`Starting server at ${port}`);
});
app.use(express.static('public'));
app.use(express.json({ limit: '1mb' }));
// when there's a request from a client for data,
app.get('/air', async (request, response) => {
// ask the openaq api for the latest
const aq_url = 'https://api.openaq.org/v2/latest?limit=500';
const aq_response = await fetch(aq_url);
const aq_data = await aq_response.json();
// send the response back to the client
response.json(aq_data);
});