Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Fikirte mulugeta assignment3 #28

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions routes/cities.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
const express = require('express');
const router = express.Router();

//path for data.json file
const cities = require('../data/cities.json');

console.log('Server started')

//call all records from json file
router.get('/', function (req, res, next){
res.json(cities);
});

//call one of the cities from the json file
router.get('/:id', function (req, res, next) {

const Cities = cities.find((city) => city.id === parseInt(req.params.id));

if (Cities){
res.json(Cities);

} else {
res.status(200).json({});

}

});

module.exports = router;