-
-
Save M-Naveed-Ashraf/5084d05134273ddd668cbd1d06244e4c to your computer and use it in GitHub Desktop.
Codecademy export ... GET API request getting only one document from collection of documents .... express practice
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const express = require('express'); | |
| const app = express(); | |
| const PORT = process.env.PORT || 4001; | |
| const battlefields = { | |
| fortSumter: { | |
| state: 'SC', | |
| }, | |
| manassas: { | |
| state: 'VA', | |
| }, | |
| gettysburg: { | |
| state: 'PA', | |
| }, | |
| antietam: { | |
| state: 'MD', | |
| } | |
| } | |
| app.listen(PORT, () => { | |
| console.log(`Server is listening on port ${PORT}`); | |
| }); | |
| app.get('/battlefields/:name', (req, res, next) => { | |
| const battlefieldName = req.params.name; | |
| const battlefield = battlefields[battlefieldName]; | |
| if(battlefield) { | |
| res.send(battlefield); | |
| } else { | |
| res.status(404).send(); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment