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..fc596a3 100644 --- a/zip-api/app.js +++ b/zip-api/app.js @@ -1,29 +1,25 @@ -const express = require('express'); +const express = require("express"); const app = express(); - -const zipdb = require('./zipData'); +// imports csv in the data folder +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) => { + res.send(zipdb.byZip[req.params.zipcode]); }); - -app.get('/city/:cityname', (req, res) => { - // fill in... +app.get("/city/:cityname", (req, res) => { + res.send(zipdb.byCity[req.params.cityname]); }); - +// the keys are upper case like BROOKLYN app.listen(PORT, () => { - console.log(`zip-api is up and running on ${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..8cecf59 100644 --- a/zip-api/package.json +++ b/zip-api/package.json @@ -1,19 +1,19 @@ { - "name": "zip-api", - "version": "1.0.0", - "description": "Simple API backend for CTP lecture.", - "main": "app.js", - "scripts": { - "start": "node app.js" - }, - "author": "Edgardo Molina", - "license": "ISC", - "dependencies": { - "csv-parse": "^4.12.0", - "express": "^4.17.1", - "morgan": "^1.10.0" - }, - "devDependencies": { - "nodemon": "^1.19.4" - } + "name": "zip-api", + "version": "1.0.0", + "description": "Simple API backend for CTP lecture.", + "main": "app.js", + "scripts": { + "start": "node app.js" + }, + "author": "Edgardo Molina", + "license": "ISC", + "dependencies": { + "csv-parse": "^4.12.0", + "express": "^4.17.1", + "morgan": "^1.10.0" + }, + "devDependencies": { + "nodemon": "^1.19.4" + } }