const express = require("express");
const app = express();
const courses = [
{ id: 1, name: "uday1" },
{ id: 2, name: "uday2" },
{ id: 3, name: "uday3" },
{ id: 4, name: "uday4" },
];
app.get("/api/courses/:id", (req, res) => {
const course = courses.find((c) => c.id === parseInt(req.params.id));
if (!course) res.status(404).send("The course ID not found");
res.send(course);
});
app.listen(3000, () => console.log("listening"));
const port = process.env.PORT || 3000;
//http://localhost:3000/api/courses/11
No comments:
Post a Comment