Node JS
Node JS
Course Objectives:
Upon completing this course, the students will be able to
List of Experiments:
1. Build a responsive web application for shopping cart with registration, login, catalog and cart pages using CSS3
features, flex and grid.
2. Make the above web application responsive web application using the Bootstrap framework.
3. Use JavaScript to validate the client-side pages implemented in experiment 1 and experiment 2.
4. Explore the features of ES6 like arrow functions, callbacks, promises, and async/await. Implement an
application for reading the weather information from [Link] and display the information as a
graph on the web page.
5. Develop a Java standalone application that connects with the database (Oracle / MySQL) and
perform the CRUD operation on the database tables.
6. Create an XML for the bookstore. Validate the same using both the DTD and XSD Programs.
7. Design a controller with a servlet that provides the interaction with an application developed in
experiment 1 and the database created in experiment 5
8. Maintaining the transactional history of any user is very important. Explore the various session-tracking
mechanisms.
9. HTTP Session: An HTTP session is a way to store information on the server side between requests
from the same client. Each client gets a unique session ID, which is used to retrieve session data.
10. Create a custom server using the HTTP module and explore the other modules of Node JS like OS,
path, and event.
11. Develop an express application that can interact with REST API to perform CRUD operation on
student data.
i
12. For the above application create authorized endpoints using JWT(JSON WEB TOKEN).
13. Create a React application for the student management system having registration, login, contact, and
about pages and implement routing to navigate through these pages.
14. Create a TODO application in react with necessary components and deploy it on github.
ii
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
VISION
MISSION
IM4: involve in activities with team spirit and collaborations towards nation building.
To be in the frontier of computer science and engineering education with moral values towards
nation-building.
Mission
DM1: To disseminate and develop knowledge with innovative ideas.
DM2: To Provide a learning-centric environment to design, experience, and encourage industry-institute
interactions.
DM3: To Organize training and involve in activities towards developing and professionals, leaders.
iii
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
PSO1 PSO 1: An ability to specify, analyze & design efficient computer applications
that meeting
PSO3 Able to excel in competitive exams and best for higher studies with technical
competency.
iv
PROGRAM OUTCOMES (POS):
PO1 Engineering knowledge: Apply the knowledge of mathematics, science, engineering
Fundamentals and an engineering specialization to the solution of complex
engineering problems.
Problem analysis: Identify, formulate, review research literature, and analyze complex
PO2 engineering problems reaching substantiated conclusions using first principles
Mathematics, natural sciences, and engineering sciences.
Modern tool usage: Create, select, and apply appropriate techniques, resources,
PO5 and modern engineering and IT tools including prediction and modeling to
complex engineering activities with an understanding of the limitations.
The engineer and society: Apply reasoning informed by the contextual knowledge
PO6 to assess societal, health, safety, legal and cultural issues and the consequent
responsibilities relevant to the professional engineering practice.
Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
PO8 norms of the engineering practice.
v
MOTHER TERESA INSTITUTE OF SCIENCE & TECHNOLOGY
Sathupally, Khammam Dist., Telangana
Department of COMPUTER SCIENCE AND ENGINEERING(AI&ML)
Blooms
CO# Course Outcomes Taxonomy
Levels
CO5 CREATE
Develop tracking mechanism (Cookies,
HTTP Session)
CO6 Design and Develop programs CREATE
application create authorized end points
using JWT (JSON Web Token).
vi
PO PO PO PO P PO PO PO PO PO1 PO1 PO1 PSO PSO PSO
O
1 2 3 4 6 7 8 9 0 1 2 1 2 3
5
1
CO1 2 2 3 1 2 2 1 3 1 2 3 2 2 2
1 1 1
CO2 2 3 2 3 2 2 2 3 2 3 2 2
1 1 1 1
CO3 3 2 3 3 2 2 1 3 2 2 3
1 1
CO4 3 3 2 2 1 1 2 2 3 1 3 2 1
2 1 1 1 1 1 1
CO5 3 2 2 2 2 2 2 2
1 1 1 1 1 1 1
CO6 3 1 1 1 2 1 2 1
Course 2.5 1.4 3 1.25 2.5 1.25 0.75 1.5 0.75 1.5 2.25 2.25 2.75 2 2
Faculty Signature
vii
Do’s and Dont’s
DO’s:
3. Take care of your eyes, by relaxing few minutes while using computer
4. Adjust the chair settings to adopt your body for the proper height and
lumbar support.
6. Operate the computer system and other hardware devices with care
Dont’s:
1. Software maybe installed by the Computer Lab staff only. Do not install any
software on your own. Unnecessary files found in the system will be
removed by the concerned staff.
3. Do not modify any software or files . Do not over write the operating system
or any other parameters in the computer system.
5. External devices like pen drive ,CD’s should be avoided so that computer
systems are free from virus.
viii
INDEX
2. Make the above web application responsive web applica using the Bootstrap
framework.
4. Explore the features of ES6 like arrow functions, callbacks, promises, and
async/await. Implement an application for reading the weather information
from [Link] and display the information in the form of a graph
on the web page.
6. Create an XML for the bookstore. Validate the same using both the DTD
and XSD Programs.
7. Design a controller with servlet that provides the interaction with an
application developed in experiment 1 and the database created in
experiment 5.
10. Create a custom server using HTTP module and explore the other
modules of Node JS like OS, path, and event.
ix
11. Develop an express application that can interact with REST API
to perform CRUD operation on student data.
12. For the above application create authorized endpoints using JWT(JSON
WEB TOKEN).
13. Create a React application for the student management system having
registration, login, contact, and about pages and implement routing to
navigate through these pages.
14. Create a TODO application in react with necessary components and
deploy it on github.
x
Mother Teresa Institute of Science and Technology
1. Build a responsive web application for shopping cart with registration, login, catalog and cart pages
using CSS3 features, flex and grid.
AIM:
Building a responsive web application for a shopping cart with registration login, catalog and cart pages
using CSS3 features, flex, and grid.
Process:
• Install Visual Studio code on your computer.
• Create an HTML file and save it as the [Link].
• Create a CSS file and save it as [Link].
• Create a JavaScript file and save it as [Link].
• All files should be saved in one folder.
• Now press F5 or click on the run from the HTML file.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shopping Cart App</title>
<link rel="stylesheet" href="[Link]">
</head>
<body>
<nav>
<a href="#home">Home</a>
<a href="#catalog">Catalog</a>
<a href="#cart">Cart</a>
<a href="#login">Login</a>
<a href="#register">Register</a>
</nav>
<section id="home">
<section id="register">
<h2>Register</h2>
<form id="registerForm">
<input type="text" id="username" placeholder="Username" required>
<input type="email" id="email" placeholder="Email" required>
<input type="password" id="password" placeholder="Password" required>
<button type="submit">Register</button>
</form>
</section>
<section id="login">
<h2>Login</h2>
<form id="loginForm">
<input type="text" id="loginUsername" placeholder="Username" required>
<input type="password" id="loginPassword" placeholder="Password" required>
<button type="submit">Login</button>
</form>
</section>
<section id="catalog">
<h2>Catalog</h2>
<div class="catalog-grid">
<div class="item">
<h3>Item 1</h3>
<button onclick="addToCart('Item 1')">Add to Cart</button>
</div>
<div class="item">
<h3>Item 2</h3>
<button onclick="addToCart('Item 2')">Add to Cart</button>
</div>
<div class="item">
<h3>Item 3</h3>
<button onclick="addToCart('Item 3')">Add to Cart</button>
</div>
</div>
</section>
<section id="cart">
<h2>Your Cart</h2>
<ul id="cartItems"></ul>
<button onclick="checkout()">Checkout</button>
</section>
<script src="[Link]"></script>
</body>
</html>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
box-sizing: border-box;
}
nav {
display: flex;
justify-content: space-around;
background-color: #333;
padding: 1rem;
}
nav a {
color: white;
text-decoration: none;
}
h1, h2 {
text-align: center;
}
.catalog-grid {
display: grid;
gap: 20px;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
padding: 1rem;
}
.item {
form {
max-width: 300px;
margin: auto;
padding: 1rem;
display: flex;
flex-direction: column;
}
input {
margin-bottom: 1rem;
padding: 0.5rem;
font-size: 1rem;
}
button {
padding: 0.5rem;
background-color: #333;
color: white;
border: none;
cursor: pointer;
}
button:hover {
background-color: #555;
}
#cartItems {
list-style: none;
padding: 0;
}
#cartItems li {
padding: 1rem;
border-bottom: 1px solid #ccc;
}
function addToCart(item) {
[Link](item);
displayCart();
}
function displayCart() {
const cartItems = [Link]("cartItems");
[Link] = "";
[Link](removeBtn);
[Link](li);
});
}
function removeFromCart(index) {
[Link](index, 1);
displayCart();
function checkout() {
if ([Link] > 0) {
alert("Checkout Successful");
cart = [];
displayCart();
} else {
alert("Your cart is empty");
}
}
OUTPUT :
2. Make the above web application responsive web application using the Bootstrap framework.
AIM1:
Making the above web application responsive web application using Bootstrap framework.
Process:
• Create an HTML file and save it as the [Link].
• Now press F5 or click on the run from the HTML file.
HTML Program:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ShopApp</title>
<link rel="stylesheet" href="[Link]
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="#">ShopApp</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ml-auto">
<li class="nav-item"><a class="nav-link" href="#home">Home</a></li>
<li class="nav-item"><a class="nav-link" href="#catalog">Catalog</a></li>
<li class="nav-item"><a class="nav-link" href="#cart">Cart</a></li>
<li class="nav-item"><a class="nav-link" href="#login">Login</a></li>
<li class="nav-item"><a class="nav-link" href="#register">Register</a></li>
</ul>
</div>
</nav>
<script src="[Link]
<script src="[Link]
<script src="[Link] </body>
</html>
OUTPUT:
3. Use JavaScript for doing client-side validation of the pages implemented in experiment 1 and experiment 2.
AIM:
Using JavaScript for doing client-side validation of the pages implemented in experiment 1 and
experiment 2.
Process:
• Create a JAVASCRIPT file and save it as the [Link].
• In experiment 1 take the same HTML file and modify the following code.
• Now press F5 or click on the run from the HTML file.
<script src="[Link]"></script>
JAVASCRIPT Program:
if ([Link] < 6) {
alert("Password must be at least 6 characters long.");
return;
}
alert("Registration Successful");
});
if (!loginUsername || !loginPassword) {
alert("Please enter both username and password.");
return;
}
alert("Login Successful");
});
function addToCart(item) {
[Link](item);
displayCart();
}
function displayCart() {
const cartItems = [Link]("cartItems");
[Link] = "";
[Link](removeBtn);
[Link](li);
});
}
function removeFromCart(index) {
[Link](index, 1);
displayCart();
}
function checkout() {
if ([Link] > 0) {
alert("Checkout Successful");
cart = [];
displayCart();
} else {
alert("Your cart is empty");
}
}
OUTPUT:
4. Explore the features of ES6 like arrow functions, callbacks, promises, and async/await. Implement an
application for reading the weather information from [Link] and display the information in
the form of a graph on the web page.
AIM:
Exploring the features of ES6 like arrow functions, callbacks, promises, and async/await. Implementing
an application for reading the weather information from [Link] and displaying the
information in the form of a graph on the web page.
Process:
• Create an HTML file and save it as the [Link]
• Create a CSS file and save it as [Link]
• Create a JAVASCRIPT file and save it as [Link] • Now press F5 or click on the run from
the HTML file.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Weather Information</title>
<link rel="stylesheet" href="[Link]">
<script src="[Link]
</head>
<body>
<div class="container">
<h1>Weather Forecast</h1>
<input type="text" id="cityInput" placeholder="Enter city name">
<button onclick="getWeatherData()">Get Weather</button>
<canvas id="weatherChart"></canvas>
</div>
<script src="[Link]"></script>
</body>
</html>
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f0f2f5;
}
.container {
width: 80%;
max-width: 600px;
text-align: center;
}
h1 {
margin-bottom: 20px;
}
input {
padding: 10px;
margin-bottom: 10px;
width: 70%;
font-size: 16px;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
}
canvas {
margin-top: 20px;
}
JAVASCRIPT Program:
fill: false,
tension: 0.1
}]
},
options: {
responsive: true,
plugins: {
legend: {
display: true
}
},
scales: {
y: {
beginAtZero: true,
title: {
display: true,
text: 'Temperature (°C)'
}
},
x: {
title: {
display: true,
text: 'Time'
}
}
}
}
});
};
OUTPUT:
5. Develop a Java standalone application that connects with the database (Oracle / MySQL) and
perform the CRUD operation on the database tables.
AIM:
Developing a Java standalone application that connects with the database (Oracle / MySQL) and
perform the CRUD operation on the database tables.
Process:
• Install Java Development Kit (JDK) on your computer.
• Install a Database like MySQL.
• Download JDBC Driver for MySQL.
• Create the java file and save it as [Link]
• Create a java file and save it as [Link]
• Create a java file and save it as [Link] • The files should be saved based on the
below structure.
• MyCRUDApp/
├── src/
│ ├── [Link]
│ ├── [Link]
│ ├── [Link]
└── lib/
└── [Link] (MySQL Connector JAR file)
• In the command prompt give the path of the Java program and connect \ MySQL to the Java
file
• Follow the below command to run java -cp .;..\lib\[Link] Main
STEP 1:
Open MySQL and create a table as follows
CREATE DATABASE MyDatabase;
USE MyDatabase;
import [Link];
while (true) {
[Link]("\n1. Add User\n2. View Users\n3. Update User\n4. Delete User\n5. Exit");
[Link]("Choose an option: ");
int choice = [Link]();
switch (choice) {
case 1:
[Link]("Enter name: ");
String name = [Link]();
[Link]("Enter email: ");
String email = [Link]();
[Link]("Enter age: ");
int age = [Link]();
[Link](name, email, age);
break;
case 2:
[Link]();
break;
case 3:
[Link]("Enter user ID to update: ");
int id = [Link]();
[Link]("Enter new name: ");
name = [Link]();
[Link]("Enter new email: ");
email = [Link]();
[Link]("Enter new age: ");
age = [Link]();
[Link](id, name, email, age);
break;
case 4:
[Link]("Enter user ID to delete: ");
id = [Link]();
[Link](id);
break;
case 5:
[Link]("Exiting...");
[Link]();
[Link](0);
default:
[Link]("Invalid choice.");
}
}
}
}
JAVA PROGRAM: [Link]
import [Link];
import [Link];
import [Link];
import [Link].*;
[Link]();
[Link]("User added successfully.");
} catch (SQLException e) {
[Link]();
}
}
public void update(int id, String name, String email, int age) {
String sql = "UPDATE Users SET name = ?, email = ?, age = ? WHERE id = ?";
try (Connection conn = [Link]();
PreparedStatement pstmt = [Link](sql)) {
[Link](1, name);
[Link](2, email);
[Link](3, age);
[Link](4, id);
[Link]();
[Link]("User updated successfully.");
} catch (SQLException e) {
[Link]();
}
}
OUTPUT:
6. Create an XML for the bookstore. Validate the same using both the DTD and XSD Programs.
AIM:
Creating an XML for the bookstore. Validating the same using both the DTD and XSD Programs.
Process:
• Create an XML file and save it as [Link].
• Create a DTD file and save it as [Link]
• Create an XSD file and save it as a bookstore,xsd
• Create a java file and save it as [Link]
• Now follow the commands o Give the file path
o javac [Link] \\ press enter o
java XMLDTDValidator \\ press enter
• the file structure is bookstore_project/
│
├── [Link]
├── [Link]
├── [Link]
├── [Link]
XML Program: [Link]
XSD Program:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="[Link]
<xs:element name="bookstore">
<xs:complexType>
<xs:sequence>
<xs:element name="book" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="author" type="xs:string"/>
<xs:element name="price" type="xs:decimal"/>
</xs:sequence>
<xs:attribute name="category" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
// Create a SAXParser
SAXParser parser =
[Link]();
[Link]().setErrorHandler(ne
w ErrorHandler() {
public void
warning(SAXParseException exception) {
[Link]("Warning: " +
[Link]());
}
public void
error(SAXParseException exception) {
[Link]("Error: " +
[Link]());
}
public void
fatalError(SAXParseException exception) {
[Link]("Fatal Error:
" + [Link]());
}
});
} catch (Exception e) {
[Link]("XML is invalid: "
+ [Link]());
}
}
}
OUTPUT:
7. Design a controller with servlet that provides the interaction with an application developed in experiment 1
and the database created in experiment 5.
AIM:
Designing a controller with servlet that provides the interaction with an application developed in
experiment 1 and the database created in experiment 5
Process
• The file structure is
/project-folder/
└── com/
└── example/
└── shoppingcart/
└── [Link]
• Create Java file save as [Link]
JAVA Program:
import [Link];
import [Link];
OUTPUT:
8. Maintain the transactional history of any user is very important. Explore the various session tracking
mechanism.
AIM:
Maintaining the transactional history of any user is very important. Exploring the various session
tracking mechanism.
Process:
• Install python in your system.
• Create a new folder and save it as Project.
• In the project file create a new file and save it as templates.
Project/
├── [Link]
└── templates/
├── [Link]
└── [Link]
• Save the Python code in the project folder and save the HTML in the templates folder as shown in
the pictures.
• Now follow the following commands in the command prompt to run o python --version // press
enter o pip install flask // press enter
o Give the path of the saved project folder (eg: C:\User\Desktop\project ) o
Python [Link] // press enter o [Link] // click on the URL
as shown in the picture
import [Link];
import [Link];
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="[Link]" >
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Language Preference</title>
</head>
<body>
<div class="container">
<h1>Language Preference</h1>
<form action="/set_language/en" method="get">
<button type="submit">Set Language to English</button>
</form>
<form action="/set_language/es" method="get">
<button type="submit">Set Language to Spanish</button>
</form>
<form action="/get_language" method="get">
<button type="submit">Get Language Preference</button>
</form>
<form action="/delete_language" method="get">
<button type="submit">Delete Language Preference</button>
</form>
</div>
</body>
</html>
h1 { margin-bottom:
20px; color: #333;
}
button { background-color:
#007BFF; color: #fff;
border: none;
padding: 10px
20px; margin: 10px;
border-radius: 5px;
cursor: pointer; font-
size: 16px;
}
button:hover {
background-color: #0056b3;
}
OUTPUT:
9. HTTP Session: An HTTP session is a way to store information on the server side between requests from the
same client. Each client gets a unique session ID, which is used to retrieve session data.
Process
• Install python in your system.
• Create a new folder and save it as Project.
• In the project file create a new file and save it as templates.
• Project/
├── [Link] # Python file (main application code)
└── templates/
├── [Link] # HTML file (for rendering)
└── [Link] # CSS file (for styling)
• Save the Python code in the project folder and save the HTML and CSS code in the templates
folder as shown in the pictures
• Now follow the following commands in the command prompt to run o python --version // press
enter o pip install flask // press enter
o Give the path of the saved project folder (eg: C:\User\Desktop\project ) o Python
[Link] // press enter
o [Link] // click on the URL to open the output
as shown in the picture
app = Flask(__name__)
app.secret_key = 'your_secret_key'
@[Link]('/')
def index():
visit_count = [Link]('visits', 0)
return render_template('[Link]', visits=visit_count)
@[Link]('/visit')
def visit():
if 'visits' in session:
session['visits'] += 1
else:
session['visits'] = 1
return redirect(url_for('index'))
@[Link]('/reset')
def reset():
[Link]('visits', None)
return redirect(url_for('index'))
if __name__ == '__main__':
[Link](debug=True)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Visit Counter</title>
<link rel="stylesheet" href="[Link]">
</head>
<body>
<div class="container">
<h1>Visit Counter</h1>
<p>Welcome back! This is your visit number: <strong>{{ visits }}</strong></p>
<form action="{{ url_for('visit') }}" method="get">
<button type="submit">Increment Visit Count</button>
</form>
<form action="{{ url_for('reset') }}" method="get">
<button type="submit">Reset Count</button>
</form>
</div>
</body>
</html>
body {
font-family: Arial, sans-serif;
text-align: center;
padding: 50px;
}
.container {
display: inline-block;
padding: 20px;
border: 2px solid #4CAF50;
border-radius: 8px;
box-shadow: 2px 2px 10px
rgba(0, 0, 0, 0.1);
}
button {
background-color: #4CAF50;
color: white;
border: none;
padding: 10px 20px;
margin: 10px;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
OUTPUT:
10. Create a custom server using HTTP module and explore the other modules of Node JS like OS, path, and
event.
AIM:
Creating a custom server using the HTTP module and exploring the other modules of Node JS like OS,
path, and event
Process
• Install [Link] in your system.
• Save the js file as the [Link].
• Follow the following commands in command prompt. o Node –version // press enter.
o Give the path of the saved js file (eg: C:\User\Desktop\ ).
o node [Link] // press enter.
o [Link] // click on URL to open the output. As shown in picture
[Link]('homePageVisit');
[Link](200, { 'Content-
Type': 'text/plain' });
[Link]('Welcome to the Home
Page!\n');
} else if ([Link] === '/os') {
[Link](200, { 'Content-
Type': 'text/plain' });
[Link](`Operating System Info: -
Platform: ${[Link]()}
- CPU Architecture: ${[Link]()}
- Total Memory: ${([Link]() /
1e9).toFixed(2)} GB
- Free Memory: ${([Link]() /
1e9).toFixed(2)} GB
- Uptime: ${([Link]() /
3600).toFixed(2)} hours
`);
} else if ([Link] === '/path') {
[Link](200, { 'Content-
Type': 'text/plain' });
const filePath = __filename;
[Link](`Path Module Info:
- File Name:
${[Link](filePath)}
- Directory Name:
${[Link](filePath)}
- Extension: ${[Link](filePath)}
`);
} else {
[Link](404, { 'Content-
Type': 'text/plain' });
[Link]('Page Not Found');
}
};
[Link]('homePageVisit', () =>
{
[Link]('Home page was
visited');
});
const server =
[Link](requestHandler);
OUTPUT:
11. Develop an express application that can interact with REST API to perform CRUD operations
on student data.
AIM:
Developing an express application that can interact with REST API to perform CRUD operations
on student data.
Process:
• Create a new folder and save it as student-crud-API
• Create the HTML file and save it as [Link] • Create a JAVASCRIPT file and save it as a
[Link]
• The files should be saved in the below structure.
student-crud-API/
|── [Link]
└── [Link]
HTML Program:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
body {
margin: 30px;
.container {
width: 50%;
margin: 0 auto;
.form-group {
margin-bottom: 15px;
width: 100%;
padding: 10px;
margin: 5px 0;
button {
background-color: #28a745;
color: white;
border: none;
cursor: pointer;
button:hover {
background-color: #218838;
table {
width: 100%;
margin-top: 30px;
border-collapse: collapse;
table, th, td {
th, td {
padding: 12px;
text-align: left;
</style>
</head>
<body>
<div class="container">
<div class="form-group">
</div>
<div class="form-group">
</div>
<div class="form-group">
</div>
<table id="students-table">
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>Email</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<script src="[Link]"></script>
</body>
</html>
JAVASCRIPT Program:
[Link]('DOMContentLoaded', loadStudents);
function loadStudents() {
[Link] = '';
[Link] = `
<td>${[Link]}</td>
<td>${[Link]}</td>
<td>${[Link]}</td>
<td>
<button onclick="editStudent(${index})">Edit</button>
<button onclick="deleteStudent(${index})">Delete</button>
</td>
`;
[Link](row);
});
function addStudent() {
return;
[Link]('name').value = '';
[Link]('age').value = '';
[Link]('email').value = '';
loadStudents();
function deleteStudent(index) {
[Link]('students', [Link](students));
loadStudents();
function editStudent(index) {
[Link]('name').value = [Link];
[Link]('age').value = [Link];
[Link]('email').value = [Link];
[Link] = function() {
updateStudent(index);
};
function updateStudent(index) {
return;
[Link]('students', [Link](students));
[Link]('name').value = '';
[Link]('age').value = '';
[Link]('email').value = '';
[Link]('button').textContent = 'Add Student';
loadStudents();
OUTPUT:
12. For the above application create authorized endpoints using JWT.
AIM:
Creating authorized endpoints.
Process:
• Create an html file and save it as [Link]
• Create a JAVASCRIPT file and save it as [Link]
HTML Program:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
body {
margin: 30px;
.container {
width: 50%;
margin: 0 auto;
.form-group {
margin-bottom: 15px;
width: 100%;
padding: 10px;
margin: 5px 0;
button {
background-color: #28a745;
color: white;
border: none;
cursor: pointer;
button:hover {
background-color: #218838;
table {
width: 100%;
margin-top: 30px;
border-collapse: collapse;
table, th, td {
th, td {
padding: 12px;
text-align: left;
.hidden {
display: none;
</style>
</head>
<body>
<div class="container">
<div id="login-form">
<div class="form-group">
</div>
<div class="form-group">
</div>
<button onclick="login()">Login</button>
</div>
<button onclick="logout()">Logout</button>
<div class="form-group">
</div>
<div class="form-group">
</div>
<div class="form-group">
</div>
<table id="students-table">
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>Email</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
<script src="[Link]"></script>
</body>
</html>
JAVASCRIPT Program:
const fakeUser = {
username: 'admin',
password: 'password123',
};
function createJWT(username) {
function validateJWT(token) {
try {
} catch {
return null;
return null;
function login() {
fakeJWT = createJWT(username);
alert('Login successful!');
[Link]('login-form').[Link]('hidden');
[Link]('app').[Link]('hidden');
[Link]('user').textContent = username;
loadStudents();
} else {
function logout() {
fakeJWT = null;
[Link]('login-form').[Link]('hidden');
[Link]('app').[Link]('hidden');
[Link]('username').value = '';
[Link]('password').value = '';
function loadStudents() {
if (!validateJWT(fakeJWT)) {
logout();
return;
[Link] = '';
[Link] = `
<td>${[Link]}</td>
<td>${[Link]}</td>
<td>${[Link]}</td>
<td>
<button onclick="editStudent(${index})">Edit</button>
<button onclick="deleteStudent(${index})">Delete</button>
</td>
`;
[Link](row);
});
function addStudent() {
if (!validateJWT(fakeJWT)) {
logout();
return;
return;
[Link]('students', [Link](students));
[Link]('name').value = '';
[Link]('age').value = '';
[Link]('email').value = '';
loadStudents();
function deleteStudent(index) {
[Link](index, 1);
[Link]('students', [Link](students));
loadStudents();
function editStudent(index) {
[Link]('name').value = [Link];
[Link]('age').value = [Link];
[Link]('email').value = [Link];
[Link] = function () {
updateStudent(index);
};
function updateStudent(index) {
return;
[Link]('students', [Link](students));
[Link]('button').onclick = addStudent;
[Link]('name').value = '';
[Link]('age').value = '';
[Link]('email').value = '';
loadStudents();
OUTPUT:
13. Create an application for the student management system having registration, login, contact,
and about pages and implement routing to navigate through these pages.
AIM:
Creating an application for the student management system having registration, login,
contact, and about pages and implementing routing to navigate through these pages.
Process:
• Create an HTML file and save it as [Link]
• Create a JAVASCRIPT file and save it as [Link]
• Create a JAVASCRIPT file and save it as [Link] • Create a JAVASCRIPT file and save it as
[Link]
• Create a JAVASCRIPT file and save it as [Link]
• Create a JAVASCRIPT file and save it as [Link] • Create a JAVASCRIPT file and save it as
[Link]
• All files should save in one folder.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
body {
margin: 0;
padding: 0;
background-color: #f4f4f4;
nav {
background-color: #333;
color: white;
padding: 10px;
nav a {
color: white;
margin: 0 10px;
text-decoration: none;
nav a:hover {
text-decoration: underline;
.container {
padding: 20px;
</style>
</head>
<body>
<div id="navbar"></div>
<script src="[Link]"></script>
<script src="[Link]"></script>
<script src="[Link]"></script>
<script src="[Link]"></script>
<script src="[Link]"></script>
<script src="[Link]"></script>
</body>
</html>
[Link] = `
<nav>
<a href="#home">Home</a>
<a href="#about">About</a>
<a href="#contact">Contact</a>
<a href="#login">Login</a>
<a href="#register">Register</a>
</nav>
`;
Navbar();
function renderPage() {
const route = [Link](1);
let content = "";
switch (route) {
case "about":
content = About();
break;
case "contact":
content = Contact();
break;
case "login":
content = Login();
break;
case "register":
content = Registration();
break;
default:
content = "<h1>Welcome to Student Management System</h1>";
break;
}
[Link]("content").innerHTML = content;
}
[Link]("hashchange", renderPage);
renderPage();
About() {
return `
<h1>About Us</h1>
`;
Contact() {
return `
<h1>Contact Us</h1>
`;
function Login() {
return `
<h1>Login</h1>
<form>
<label>Email:</label>
<br>
<label>Password:</label>
<br>
<button type="submit">Login</button>
</form>
`;
<h1>Registration</h1>
<form>
<label>Name:</label>
<br>
<label>Email:</label>
<br>
<label>Password:</label>
<br>
<button type="submit">Register</button>
</form>
`;
OUTPUT:
14. Create a TODO application in react with necessary components and deploy it on github.
AIM:
Creating a TODO application in react with necessary components and deploying it on github.
Procedure:
1. Set up the React App:
npx create-react-app todo-
appcd todo-app
2. Js program: [Link]
Js program: [Link]
</div>
);
};
Js program: [Link]
return (
<form onSubmit={handleSubmit}>
<input
type="text"
value={newTask}
onChange={(e) => setNewTask([Link])}
placeholder="Add a new task"
/>
<button type="submit">Add</button>
</form>
);
};
Js program: [Link]
return (
<div style={{ textAlign: 'center', margin: '20px' }}>
<h1>TODO App</h1>
<TodoForm onAddTask={addTask} />
<TodoList tasks={tasks} onDelete={deleteTask} />
</div>
);
};
"homepage": "[Link]
"scripts": {
"predeploy": "npm run build",
"deploy": "gh-pages -d build"
}
OUTPUT: