Program 12
Program 12
Develop a web application to manage student information using Express and Angular
JS
We can develop a web application to manage student information using Express.js (Node.js
backend) and AngularJS (frontend).
Install Dependencies
mkdir student-management
cd student-management
npm init -y
// Middleware
app.use(cors());
app.use(bodyParser.json());
// Database Connection
mongoose
// Routes
app.use("/students", studentRoutes);
app.listen(PORT, () => {
});
models/student.js
name: String,
age: Number,
course: String,
});
routes/students.js
res.json(students);
});
// Add a student
await student.save();
res.json(student);
});
// Delete a student
await Student.findByIdAndDelete(req.params.id);
});
module.exports = router;
2. Frontend (AngularJS)
Setup Frontend
mkdir ../frontend
cd ../frontend
npm init -y
index.html
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>Student Management</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
<script src="app.js"></script>
<script src="controllers/studentController.js"></script>
<script src="services/studentService.js"></script>
</head>
<body ng-controller="StudentController">
<h2>Student Management</h2>
<form ng-submit="addStudent()">
</form>
<ul>
<button ng-click="deleteStudent(student._id)">Delete</button>
</li>
</ul>
</body>
</html>
app.js
controllers/studentController.js
$scope.students = [];
$scope.getStudents = function () {
StudentService.getStudents().then(function (response) {
$scope.students = response.data;
});
};
$scope.addStudent = function () {
StudentService.addStudent($scope.newStudent).then(function () {
$scope.newStudent = {};
$scope.getStudents();
});
};
StudentService.deleteStudent(id).then(function () {
$scope.getStudents();
});
};
$scope.getStudents();
});
services/studentService.js
this.getStudents = function () {
return $http.get("http://localhost:5000/students");
};
};
};
});
cd backend
node server.js