From 4afa05c5925d07da66ada7eccd8005db34ce1ec7 Mon Sep 17 00:00:00 2001 From: Edward Paez Date: Sat, 23 Oct 2021 16:25:37 -0400 Subject: [PATCH] Lab finished --- package-lock.json | 3 +++ zip-api/app.js | 25 ++++++++++--------------- zip-api/package.json | 3 ++- 3 files changed, 15 insertions(+), 16 deletions(-) create mode 100644 package-lock.json 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",