FSD Lab Program-12
FSD Lab Program-12
12. Develop a web application to manage student information using Express and Angular
JS
Make sure you have Node.js installed. Then install Express and CORS:
let students = [
];
res.json(students);
});
newStudent.id = students.length + 1;
students.push(newStudent);
});
});
app.listen(PORT, () => {
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
<style>
body
margin: 20px;
table
width: 100%;
border-collapse: collapse;
th, td
padding: 8px;
text-align: left;
th
background-color: #f2f2f2;
</style>
</head>
<form ng-submit="addStudent()">
<label>Name:</label>
<label>Course:</label>
<button type="submit">Add</button>
</form>
<h3>Student List</h3>
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Course</th>
<th>Actions</th>
</tr>
<td><button ng-click="deleteStudent(student.id)">Delete</button></td>
</tr>
</table>
<script>
function loadStudents() {
$http.get(apiUrl).then(response => {
$scope.students = response.data;
}).catch(error => {
});
$scope.addStudent = function() {
alert(response.data.message);
});
};
// Delete student
$scope.deleteStudent = function(id) {
alert(response.data.message);
loadStudents(); // Refresh the list
});
};
});
</script>
</body>
</html>
Explanation:
3. Runs on http://localhost:3000.
node server.js