Lab Manual Solution AWP 2025
Lab Manual Solution AWP 2025
1. Create a single page application for Library that will allow the librarian to add a new book and search
whether book is currently available in the library or not.
index.js
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Library System</title>
<link rel="stylesheet" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
<script src="app.js"></script>
</head>
<body ng-app="libraryApp">
<div ng-controller="LibraryController as libCtrl">
<h1>Library System</h1>
<h3>Available Books</h3>
<ul>
<li ng-repeat="book in libCtrl.books">
{{book.title}} by {{book.author}}
</li>
</ul>
<h3>Search Result:</h3>
<div ng-if="libCtrl.searchResult">
<p>{{libCtrl.searchResult.title}} by {{libCtrl.searchResult.author}} is available.</p>
</div>
<div ng-if="!libCtrl.searchResult && libCtrl.searchTitle">
<p>No book found with the title "{{libCtrl.searchTitle}}".</p>
</div>
</div>
</body>
</html>
app.js
app.controller('LibraryController', function() {
var vm = this;
vm.books = [];
vm.newBook = {};
vm.searchTitle = '';
vm.searchResult = null;
vm.addBook = function() {
vm.books.push({
title: vm.newBook.title,
author: vm.newBook.author
});
vm.newBook = {}; // Clear the input fields
};
vm.searchBook = function() {
vm.searchResult = vm.books.find(book => book.title.toLowerCase() ===
vm.searchTitle.toLowerCase()) || null;
};
});
Output
2.Write Node JS code to perform selection and updation operation to select and update specific
document in Mongo DB.
// Create database
MongoClient.connect(url, function (err, db) {
if (err) throw err;
// Create database
MongoClient.connect(url, function (err, db) {
if (err) throw err;
// Create database
MongoClient.connect(url, function(err, db) {
if (err) throw err;
const fs = require('fs');
const readline = require('readline');
node file1.js
found 0 vulnerabilities
PS C:\Users\vainshbharat\Documents\NODEJS\fileupload>
PS C:\Users\vainshbharat\Documents\NODEJS\fileupload> npm install express
found 0 vulnerabilities
PS C:\Users\vainshbharat\Documents\NODEJS\fileupload> node app.js
Server is running on http://localhost:3000
PS C:\Users\vainshbharat\Documents\NODEJS\fileupload> node app.js
Server is running on http://localhost:3000
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>File Upload</title>
</head>
<body>
<h1>Upload File</h1>
<form action="/upload" method="POST" enctype="multipart/form-data">
<input type="file" name="file" required />
<button type="submit">Upload</button>
</form>
</body>
</html>
app.js
const express = require('express');
const multer = require('multer');
const path = require('path');
Create the uploads Directory: The uploads/ folder will store the files uploaded by the user.
Ensure this folder exists in your project directory.
mkdir uploads
Access the Application: Open your browser and navigate to http://localhost:3000. You
should see the file upload form. You can browse and upload a file, and it will be saved in the
uploads directory.
Express is used to create a simple server that listens on port 3000.
Multer is used to handle file uploads. The uploaded file is stored in the uploads/ directory
with a unique filename (timestamped).
The form in index.html sends the uploaded file to the /upload route using POST. The file is
processed by multer and saved in the uploads/ folder.
Once the file is uploaded, the server sends a success message back to the user.
Design a webpage with a file input control to browse appropriate file and four buttons Read File
Synchronously, Read File Asynchronously, Compress File, and Decompress File. Implement the
functionality of all four buttons on the browsed file using Node JS.
The frontend will provide a simple file input, four buttons, and a display area to show the
result or status of each action.
2. Backend (Node.js):
We will create a backend to handle the file reading and compression/decompression using
libraries like fs (for reading files) and zlib (for compression and decompression).
Project Setup
First, ensure you have Node.js installed on your machine. Then, initialize a Node.js project:
mkdir file-compression-app
cd file-compression-app
npm init –y
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>File Compression & Decompression</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 20px;
}
.container {
max-width: 600px;
margin: auto;
text-align: center;
}
input[type="file"] {
margin: 20px 0;
}
button {
margin: 10px;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
}
#output {
margin-top: 20px;
white-space: pre-wrap;
}
</style>
</head>
<body>
<div class="container">
<h1>File Compression and Decompression</h1>
<input type="file" id="fileInput">
<div>
<button onclick="readFileSync()">Read File Synchronously</button>
<button onclick="readFileAsync()">Read File Asynchronously</button>
<button onclick="compressFile()">Compress File</button>
<button onclick="decompressFile()">Decompress File</button>
</div>
<div id="output"></div>
</div>
<script>
let selectedFile = null;
document.getElementById('fileInput').addEventListener('change', function(e) {
selectedFile = e.target.files[0];
});
function readFileSync() {
if (!selectedFile) {
alert("Please select a file first.");
return;
}
function readFileAsync() {
if (!selectedFile) {
alert("Please select a file first.");
return;
}
function decompressFile() {
if (!selectedFile) {
alert("Please select a file first.");
return;
}
Server.js
fileStream.pipe(gzip).pipe(compressedStream);
compressedStream.on('finish', () => {
res.send(`File compressed successfully: ${compressedPath}`);
});
});
fileStream.pipe(gunzip).pipe(decompressedStream);
decompressedStream.on('finish', () => {
res.send(`File decompressed successfully: ${decompressedPath}`);
});
});
<!DOCTYPE html>
<html lang="en" ng-app="myApp">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AngularJS Routing Example</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.8.2/angular-
route.min.js"></script>
</head>
<body>
<!-- Main Navigation -->
<div>
<a href="#!home">Home</a> |
<a href="#!about">About</a> |
<a href="#!contact">Contact</a>
</div>
Indx.html
<!DOCTYPE html>
<html lang="en" ng-app="myApp">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AngularJS Routing Example</title>
</head>
<body>
index.html
<!DOCTYPE html>
<html lang="en" ng-app="validationApp">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AngularJS Validation Example</title>
<script src="https://code.angularjs.org/1.8.2/angular.min.js"></script>
<style>
.error { color: red; }
.valid { color: green; }
</style>
</head>
<body>
<div ng-controller="FormController">
<h2>Signup Form</h2>
<div>
<label>Username:</label>
<input type="text" name="username" ng-model="username" required />
<span class="error" ng-show="signupForm.username.$touched &&
signupForm.username.$invalid">Username is required.</span>
</div>
<div>
<label>Password:</label>
<input type="password" name="password" ng-model="password" required ng-
minlength="6" />
<span class="error" ng-show="signupForm.password.$touched &&
signupForm.password.$invalid">Password is required and must be at least 6
characters.</span>
</div>
<div>
<button type="submit" ng-disabled="signupForm.$invalid">Submit</button>
</div>
</form>
<div ng-show="formSubmitted">
<p>Form Submitted!</p>
<p><strong>Email:</strong> {{ email }}</p>
<p><strong>Username:</strong> {{ username }}</p>
<p><strong>Password:</strong> {{ password }}</p>
</div>
</div>
<script>
var app = angular.module('validationApp', []);
app.controller('FormController', function($scope) {
$scope.formSubmitted = false;
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Customer Data</title>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
</head>
<body ng-app="customerApp" ng-controller="customerCtrl">
<h2>Customer Data</h2>
<script src="app.js"></script>
</body>
</html>
app.js
customer.php
<?php
// Customers.php file to simulate a response in JSON format
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Table with Search and Sort</title>
<style>
/* Simple styling for the table and search field */
body {
font-family: Arial, sans-serif;
margin: 20px;
}
input[type="text"] {
padding: 10px;
margin-bottom: 20px;
width: 200px;
border: 1px solid #ccc;
}
table {
width: 100%;
border-collapse: collapse;
}
th, td {
padding: 10px;
text-align: left;
border: 1px solid #ddd;
}
th {
cursor: pointer;
}
th.sortable:hover {
background-color: #f1f1f1;
}
</style>
</head>
<body>
<script>
// Function to filter records based on search input
function searchTable() {
const input = document.getElementById('searchInput').value.toUpperCase();
const table = document.getElementById('dataTable');
const tr = table.getElementsByTagName('tr');
while (switching) {
switching = false;
const rowsArray = Array.from(rows);
for (let i = 1; i < rowsArray.length - 1; i++) {
shouldSwitch = false;
const x = rowsArray[i].getElementsByTagName('TD')[n];
const y = rowsArray[i + 1].getElementsByTagName('TD')[n];
if (shouldSwitch) {
rowsArray[i].parentNode.insertBefore(rowsArray[i + 1], rowsArray[i]);
switching = true;
switchcount++;
} else {
if (switchcount === 0 && dir === 'asc') {
dir = 'desc';
switching = true;
}
}
}
}
</script>
</body>
</html>
Create a HTML form that will accept Enrolment No., Name, Semester, Branch, Mobile
Number, Email, Address etc. from the student and display them on the page using
Angular JS Directives and Expressions.
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Student Enrolment Form</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
form {
margin-bottom: 20px;
}
label {
margin-right: 10px;
}
input, textarea {
margin-bottom: 10px;
padding: 5px;
width: 300px;
}
.form-group {
margin-bottom: 15px;
}
.result {
margin-top: 20px;
padding: 10px;
background-color: #f0f0f0;
}
</style>
</head>
<body ng-app="studentApp" ng-controller="studentCtrl">
<div class="form-group">
<label for="name">Name:</label>
<input type="text" id="name" ng-model="student.name" required>
</div>
<div class="form-group">
<label for="semester">Semester:</label>
<input type="text" id="semester" ng-model="student.semester" required>
</div>
<div class="form-group">
<label for="branch">Branch:</label>
<input type="text" id="branch" ng-model="student.branch" required>
</div>
<div class="form-group">
<label for="mobile">Mobile Number:</label>
<input type="text" id="mobile" ng-model="student.mobile" required>
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="email" id="email" ng-model="student.email" required>
</div>
<div class="form-group">
<label for="address">Address:</label>
<textarea id="address" ng-model="student.address" required></textarea>
</div>
<script>
// AngularJS Application Module and Controller
var app = angular.module('studentApp', []);
app.controller('studentCtrl', function($scope) {
$scope.student = {}; // Object to store form data
Design a webpage that reads a Text file using AJAX.
Index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Read Text File with AJAX</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
#output {
margin-top: 20px;
padding: 10px;
border: 1px solid #ccc;
background-color: #f9f9f9;
white-space: pre-wrap;
word-wrap: break-word;
}
</style>
</head>
<body>
<div id="output"></div>
<script src="script.js"></script>
</body>
</html>
Script.js
document.getElementById('loadFileBtn').addEventListener('click', loadTextFile);
function loadTextFile() {
var xhr = new XMLHttpRequest();
xhr.open('GET', 'demo.txt', true); // Make sure your file is in the same directory or specify
the correct path
xhr.onload = function() {
if (xhr.status === 200) {
document.getElementById('output').textContent = xhr.responseText;
} else {
document.getElementById('output').textContent = "Error loading the file!";
}
};
xhr.onerror = function() {
document.getElementById('output').textContent = "Request failed.";
};
xhr.send();
}
Demo.txt