NodeJS Slip 11B Solution

//Slip_11B.js

const express = require('express');
const app = express();
const port = 3000;

// Sample data for courses and faculty
const courses = [
{ id: 1, name: 'Introduction to Programming', credits: 3 },
{ id: 2, name: 'Data Structures', credits: 4 },
{ id: 3, name: 'Database Management', credits: 3 },
];

const faculty = [
{ id: 101, name: 'Mrs. Swapnal Nagwade ', specialization: 'Algorithms' },
{ id: 102, name: 'Mrs. Hemalata Chavan', specialization: 'Database Systems' },
];

// Serve the home page
app.get('/', (req, res) => {
res.send('Welcome to the Computer Science Department Portal');
});

// Serve a list of courses
app.get('/courses', (req, res) => {
res.json(courses);
});
// Serve a list of faculty members
app.get('/faculty', (req, res) => {
res.json(faculty);
});

app.listen(port, () => {
console.log(`Server is running at http://localhost:${port}`);
});

No comments:

Post a Comment