diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..48e341a --- /dev/null +++ b/package-lock.json @@ -0,0 +1,3 @@ +{ + "lockfileVersion": 1 +} diff --git a/zip-api/app.js b/zip-api/app.js index df1f97b..3020796 100644 --- a/zip-api/app.js +++ b/zip-api/app.js @@ -1,29 +1,24 @@ -const express = require('express'); +const express = require("express"); const app = express(); -const zipdb = require('./zipData'); +const zipdb = require("./zipData"); const PORT = process.env.PORT || 8000; - -// console.log(zipdb.byCity); - - -app.get('/', (req, res) => { - res.json({test: 'Yay'}); +app.get("/", (req, res) => { + res.json({ test: "Yay" }); }); - -app.get('/zip/:zipcode', (req, res) => { - // fill in... +app.get("/zip/:zipcode", (req, res) => { + const zipcode = req.params.zipcode; + res.json(zipdb.byZip[zipcode]); }); - -app.get('/city/:cityname', (req, res) => { - // fill in... +app.get("/city/:cityname", (req, res) => { + const cityname = req.params.cityname; + res.json(zipdb.byCity[cityname]); }); - app.listen(PORT, () => { console.log(`zip-api is up and running on ${PORT}`); }); diff --git a/zip-api/package.json b/zip-api/package.json index 631bb53..e65db88 100644 --- a/zip-api/package.json +++ b/zip-api/package.json @@ -4,7 +4,8 @@ "description": "Simple API backend for CTP lecture.", "main": "app.js", "scripts": { - "start": "node app.js" + "start": "node app.js", + "dev": "nodemon app.js" }, "author": "Edgardo Molina", "license": "ISC",