-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
43 lines (29 loc) · 773 Bytes
/
app.js
File metadata and controls
43 lines (29 loc) · 773 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
42
43
const express = require('express');
const app = express();
const zipdb = require('./zipData');
const PORT = process.env.PORT || 8000;
// console.log(zipdb.byCity);
app.get('/', (req, res) => {
res.json({test: 'Yay'});
});
app.get('/zip/:zipcode', (req, res, next) => {
const zipInfo = zipdb.byZip[req.params.zipcode];
if(zipInfo) {
res.json(zipInfo);
} else {
//res.status(404).send("Not Found");
res.sendStatus(404);
}
});
app.get('/city/:cityname', (req, res, next) => {
const cityInfo = zipdb.byCity[req.params.cityname];
if(cityInfo) {
res.json(cityInfo);
} else {
//res.status(404).send("Not Found");
res.sendStatus(404);
}
});
app.listen(PORT, () => {
console.log(`zip-api is up and running on ${PORT}`);
});