NODE JS Lab Manual Part1
NODE JS Lab Manual Part1
Build a web application with registration, login, catalog and cart pages using CSS3
features, flex and grid.
1. Project Setup:
⦁ Create three HTML files: index.html for the landing page,
⦁ register.html for registration, and
⦁ login.html for login.
⦁ Create a separate CSS file styles.css to style all pages.
Index.html
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> SHOPPING WEBSITE </title>
<link rel="stylesheet" href="style.css">
</head>
<body align=”left">
<header>
<h1>HAPPY SHOPPING !!</h2>
</header>
<h1 align="left">Welcome to my Website..</h1>
<nav align="left">
<a href="registration.html">Registration form</a>
<a href="login.html">Login</a>
<a href="catalog.html">Catalog</a>
<a href="cart.html">Cart</a>
</nav>
</body>
</html>
Registration.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Registration Form</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<nav align="right">
<a href="index.html">Home</a>
<a href="login.html">Login</a>
<a href="catalog.html">Registration Form</a>
<a href="cart.html">Cart</a>
</nav>
<h2>Registration Form</h2>
<form action="#" method="POST">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required><br><br>
Login.html
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body align="left">
<header>
<nav align="left">
<a href="index.html">Home</a>
<a href="registration.html">Registration Form</a>
<a href="catalog.html">Catalog</a>
<a href="cart.html">Cart</a>
</nav>
</header>
<h1 align="left">LOGIN FORM</h1>
<form action="formex.html">
<table>
<tr>
<label> Name:</label>
</tr>
<tr>
<input type="text"><br>
</tr><br>
<tr>
<label>Password:</label>
</tr>
<tr>
<input type="text"><br>
</tr><br>
<label>Confirm Password:</label>
<tr>
<input type="text"><br>
</tr><br>
<button type="submit" class="btn btn-primary">Submit</button>
</table>
</form>
</body>
</html>
Catalog.html
<!DOCTYPE html>
<html lang="en">
<head>
<nav align="left">
<a href="index.html">Home</a>
<a href="registration.html">Registration Form</a>
<a href="catalog.html">Catalog</a>
<a href="cart.html">Cart</a>
</nav>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Product Catalog</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h2>Product Catalog</h2>
<div class="product">
<img src="C:\Users\sys\Downloads\register3.jpg" alt="Product">
<h3>Hair Dryer</h3>
<p>Faszin Ionic Salon Hair Dryer, Professional Blow Dryer 2200W AC Motor Fast
Drying</p>
<p>Price: $19.99</p>
<button>Add to Cart</button>
</div>
</body>
</html>
Cart.html
<!DOCTYPE html>
<html lang="en">
<body>
<nav align="left">
<a href="index.html">Home</a>
<a href="login.html">Login</a>
<a href="registration.html">Registration Form</a>
<a href="catalog.html">Catalog</a>
</nav>
</body>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shopping Cart</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h2>Shopping Cart</h2>
<div class="cart">
<h3>Cart Items</h3>
<div class="product">
<img src="C:\Users\sys\Downloads\register3.jpg" alt="Product" height="50" width="50">
<p>Hair Dryer</p>
<p>Price: $19.99</p>
<button>Remove</button>
</div>
<p>Total: $19.99</p>
<button>Checkout</button>
</div>
</body>
</html>
Styles.css
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
header {
display: flex;
justify-content: space-between;
align-items: center;
background-color: #f0f0f0;
}
nav {
display: flex;
gap: 10px;
}
main {
display: flex;
justify-content: center;
align-items: center;
min-height: calc(100vh - 160px); /* Account for header and footer heights */
}
.hero {
text-align: center;
}
OUTPUT
Index.html registration.html
Login.html
Catalog.html
Cart.html
2. Make the above web application a responsive web application using Bootstrap
framework.
1. Project Setup:
Index.html
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> SHOPPING WEBSITE </title>
<link rel="stylesheet" href="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A
NodeJs-ReactJs-Django\Lab Programs\Program-2\bootstrap-5.0.2-
dist\css\bootstrap.min.css">
<script src="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A-NodeJs-ReactJs Django\Lab
Programs\Program-2\bootstrap-5.0.2-
dist\js\bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body align="leftr">
<header>
<h1>HAPPY SHOPPING !!</h2>
</header>
<h1 align="left">Welcome to my Website..</h1>
<nav align="left">
<a href="registration.html">Registration form</a>
<a href="login.html">Login</a>
<a href="catalog.html">Catalog</a>
<a href="cart.html">Cart</a>
</nav>
</body>
</html>
Registration.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Registration Form</title>
<link rel="stylesheet" href="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A
NodeJs-ReactJs-Django\Lab Programs\Program-2\bootstrap-5.0.2-
dist\css\bootstrap.min.css">
<script src="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A-NodeJs-ReactJs Django\Lab
Programs\Program-2\bootstrap-5.0.2-
dist\js\bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<nav align="left">
<a href="index.html">Home</a>
<a href="login.html">Login</a>
<a href="catalog.html">Registration Form</a>
<a href="cart.html">Cart</a>
</nav>
<h2>Registration Form</h2>
<form action="#" method="POST">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required><br><br>
Login.html
<html>
<head>
<link rel="stylesheet" href="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A
NodeJs-ReactJs-Django\Lab Programs\Program-2\bootstrap-5.0.2-
dist\css\bootstrap.min.css">
<script src="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A-NodeJs-ReactJs Django\Lab
Programs\Program-2\bootstrap-5.0.2-
dist\js\bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body align="left">
<header>
<nav align="left">
<a href="index.html">Home</a>
<a href="registration.html">Registration Form</a>
<a href="catalog.html">Catalog</a>
<a href="cart.html">Cart</a>
</nav>
</header>
<h1 align=”left">LOGIN FORM</h1>
<form action="formex.html">
<table >
<tr>
<label> Name:</label>
</tr>
<tr>
<input type="text"><br>
</tr><br>
<tr>
<label>Password:</label>
</tr>
<tr>
<input type="text"><br>
</tr><br>
<label>Confirm Password:</label>
<tr>
<input type="text"><br>
</tr><br>
<button type="submit" class="btn btn-primary">Submit</button>
</table>
</form>
</body>
</html>
Catalog.html
<!DOCTYPE html>
<html lang="en">
<head>
<nav align="left">
<a href="index.html">Home</a>
<a href="registration.html">Registration Form</a>
<a href="catalog.html">Catalog</a>
<a href="cart.html">Cart</a>
</nav>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Product Catalog</title>
<link rel="stylesheet" href="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A
NodeJs-ReactJs-Django\Lab Programs\Program-2\bootstrap-5.0.2-
dist\css\bootstrap.min.css">
<script src="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A-NodeJs-ReactJs Django\Lab
Programs\Program-2\bootstrap-5.0.2-
dist\js\bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h2>Product Catalog</h2>
<div class="product">
<img src="C:\Users\sys\Downloads\register3.jpg" alt="Product">
<h3>Hair Dryer</h3>
<p>Faszin Ionic Salon Hair Dryer, Professional Blow Dryer 2200W AC Motor Fast
Drying</p>
<p>Price: $19.99</p>
<button>Add to Cart</button>
</div>
</body>
</html>
Cart.html
<!DOCTYPE html>
<html lang="en">
<body>
<nav align="left">
<a href="index.html">Home</a>
<a href="login.html">Login</a>
<a href="registration.html">Registration Form</a>
<a href="catalog.html">Catalog</a>
</nav>
</body>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shopping Cart</title>
<link rel="stylesheet" href="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A
NodeJs-ReactJs-Django\Lab Programs\Program-2\bootstrap-5.0.2-
dist\css\bootstrap.min.css">
<script src="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A-NodeJs-ReactJs Django\Lab
Programs\Program-2\bootstrap-5.0.2-
dist\js\bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h2>Shopping Cart</h2>
<div class="cart">
<h3>Cart Items</h3>
<div class="product">
<img src="C:\Users\sys\Downloads\register3.jpg" alt="Product" height="50" width="50">
<p>Hair Dryer</p>
<p>Price: $19.99</p>
<button>Remove</button>
</div>
<p>Total: $19.99</p>
<button>Checkout</button>
</div>
</body>
</html>
Styles.css
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
header {
display: flex;
justify-content: space-between;
align-items: center;
background-color: #f0f0f0;
}
nav {
display: flex;
gap: 10px;
}
main {
display: flex;
justify-content: center;
align-items: center;
min-height: calc(100vh - 160px); /* Account for header and footer heights */
}
.hero {
text-align: center;
}
OUTPUT
Index.html registration.html
Login.html
Catalog.html
Cart.html
3. Use JavaScript for doing client – side validation of the pages implemented in
experiment 1 and experiment 2.
1. We include a separate script.js file to store our validation logic.
2. We use JavaScript to access form elements and set up an event listener for the
form's submit event.
3. Inside the event listener, we perform basic validations for username and password
fields:
a. Checking if the field is empty using isEmpty().
b. Checking if the password meets a minimum length requirement
using minLength().
Index.html
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> SHOPPING WEBSITE </title>
<link rel="stylesheet" href="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A
NodeJs-ReactJs-Django\Lab Programs\Program-2\bootstrap-5.0.2-
dist\css\bootstrap.min.css">
<script src="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A-NodeJs-ReactJs Django\Lab
Programs\Program-2\bootstrap-5.0.2-
dist\js\bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body align="left">
<header>
<h1 >HAPPY SHOPPING !!</h2>
</header>
<h1 align="left">Welcome to my Website..</h1>
<nav align="left">
<a href="registration.html">Registration form</a>
<a href="login.html">Login</a>
<a href="catalog.html">Catalog</a>
<a href="cart.html">Cart</a>
</nav>
</body>
</html>
Registration.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Registration Form</title>
<link rel="stylesheet" href="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A NodeJs-ReactJs-Django\Lab
Programs\Program-2\bootstrap-5.0.2- dist\css\bootstrap.min.css">
<script src="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A-NodeJs-ReactJs Django\Lab
Programs\Program-2\bootstrap-5.0.2- dist\js\bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<nav align="left">
<a href="index.html">Home</a>
<a href="login.html">Login</a>
<a href="catalog.html">Registration Form</a>
<a href="cart.html">Cart</a>
</nav>
<h2>Registration Form</h2>
<form action="#" method="POST" onsubmit="return validateForm()">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required><br><br>
<script>
function validateForm() {
var name = document.getElementById("name").value;
var email = document.getElementById("email").value;
if (email.trim() == "") {
alert("Please enter your email.");
return false;
} else if (!validateEmail(email)) {
alert("Please enter a valid email address.");
return false;
}
return true;
}
function validateEmail(email) {
var re = /\S+@\S+\.\S+/;
return re.test(email);
}
</script>
</body>
</html>
Login.html
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A
NodeJs-ReactJs-Django\Lab Programs\Program-2\bootstrap-5.0.2- dist\css\bootstrap.min.css">
<script src="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A-NodeJs-ReactJs Django\Lab
Programs\Program-2\bootstrap-5.0.2- dist\js\bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body align="left">
<header>
<nav align="left">
<a href="index.html">Home</a>
<a href="registration.html">Registration Form</a>
<a href="catalog.html">Catalog</a>
<a href="cart.html">Cart</a>
</nav>
</header>
<h1 align="left">LOGIN FORM</h1>
<form action="formex.html" onsubmit="return validateForm()">
<tr>
<td><label>Name:</label></td>
</tr>
<tr>
<td><input type="text" id="name"></td>
</tr>
<br>
<tr>
<td><label>Password:</label></td>
</tr>
<tr>
<td><input type="password" id="password"></td>
</tr>
<br>
<tr>
<td><label>Confirm Password:</label></td>
</tr>
<tr>
<td><input type="password" id="confirmPassword"></td>
</tr>
<br>
<tr>
<td><button type="submit" class="btn btn-primary">Submit</button></td>
</tr>
</table>
</form>
<script>
function validateForm() {
var name = document.getElementById("name").value;
var password = document.getElementById("password").value;
var confirmPassword = document.getElementById("confirmPassword").value;
if (name.trim() == "") {
alert("Please enter your name.");
return false;
}
if (password.trim() == "") {
alert("Please enter your password.");
return false;
}
if (confirmPassword.trim() == "") {
alert("Please confirm your password.");
return false;
}
return true;
}
</script>
</body>
</html>
Catalog.html
<!DOCTYPE html>
<html lang="en">
<head>
<nav align="left">
<a href="index.html">Home</a>
<a href="registration.html">Registration Form</a>
<a href="catalog.html">Catalog</a>
<a href="cart.html">Cart</a>
</nav>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Product Catalog</title>
<link rel="stylesheet" href="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A
NodeJs-ReactJs-Django\Lab Programs\Program-2\bootstrap-5.0.2-
dist\css\bootstrap.min.css">
<script src="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A-NodeJs-ReactJs Django\Lab
Programs\Program-2\bootstrap-5.0.2-
dist\js\bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h2>Product Catalog</h2>
<div class="product">
<img src="C:\Users\sys\Downloads\register3.jpg" alt="Product">
<h3>Hair Dryer</h3>
<p>Faszin Ionic Salon Hair Dryer, Professional Blow Dryer 2200W AC Motor Fast
Drying</p>
<p>Price: $19.99</p>
<button>Add to Cart</button>
</div>
</body>
</html>
Cart.html
<!DOCTYPE html>
<html lang="en">
<body>
<nav align="left">
<a href="index.html">Home</a>
<a href="login.html">Login</a>
<a href="registration.html">Registration Form</a>
<a href="catalog.html">Catalog</a>
</nav>
</body>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shopping Cart</title>
<link rel="stylesheet" href="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A
NodeJs-ReactJs-Django\Lab Programs\Program-2\bootstrap-5.0.2-
dist\css\bootstrap.min.css">
<script src="I:\Subjects\A.Y 2023-24\Sem-2\II-II-IT-A-NodeJs-ReactJs Django\Lab
Programs\Program-2\bootstrap-5.0.2-
dist\js\bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h2>Shopping Cart</h2>
<div class="cart">
<h3>Cart Items</h3>
<div class="product">
<img src="C:\Users\sys\Downloads\register3.jpg" alt="Product" height="50" width="50">
<p>Hair Dryer</p>
<p>Price: $19.99</p>
<button>Remove</button>
</div>
<p>Total: $19.99</p>
<button>Checkout</button>
</div>
</body>
</html>
Styles.css
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
header {
display: flex;
justify-content: space-between;
align-items: center;
background-color: #f0f0f0;
}
nav {
display: flex;
gap: 10px;
}
main {
display: flex;
justify-content: center;
align-items: center;
min-height: calc(100vh - 160px); /* Account for header and footer heights */
}
.hero {
text-align: center;
}
OUTPUT
Index.html
registration.html
Login.html
Catalog.html
Cart.html
4. Explore the features of ES6 like arrow functions, callbacks, promises, async/await.
Implement an application for reading the weather information from openweathermap.org
and display the information in the form of a graph on the web page.
CODE:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Weather Graph</title>
<style>
body {
background-color: #fff;
#graph {
max-width: 800px;
#chart-container {
margin-top: 40px;
/* Change font */
#city {
font-size: 16px;
box-sizing: border-box; /* Include padding and border in the input's total width */
font-size: 18px;
#get-weather-button {
font-size: 16px;
color: #fff;
border: none;
cursor: pointer;
#get-weather-button:hover {
</style>
<link rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap">
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<body>
<div id="graph">
<br>
<br>
<div id="chart-container">
</div>
</div>
<script>
const apiUrl =
`https://api.openweathermap.org/data/2.5/forecast?q=${city}&appid=${apiKey}`;
try {
return data;
} catch (error) {
return null;
}
}
function drawGraph(data) {
chartContainer.innerHTML = '';
canvas.setAttribute('id', 'myChart');
canvas.width = 800;
canvas.height = 400;
chartContainer.appendChild(canvas);
new Chart(ctx), {
type: 'line',
data: {
labels: labels,
datasets: [{
borderColor: '#000', // Change graph line color to jet black for better visibility
data: temperatures,
}]
},
options: {
responsive: false,
scales: {
y: {
beginAtZero: true,
grid: {
color: '#888' // Set grid color to light gray for better visibility
},
ticks: {
},
x: {
grid: {
color: '#888' // Set grid color to light gray for better visibility
},
ticks: {
}
});
time: entry.dt_txt,
}));
drawGraph(temperatures);
} else {
console.error('Failed to fetch weather data or no data found for the entered city.');
</script>
5. Develop a java stand-alone application that connects with the database (Oracle
/ mySql) and perform the CRUD operation on the database tables
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/sample?useSSL=false","root","1
2345");
while(rs.next()){
if (rowsAffected > 0) {
} else {
System.out.println("Insertion failed.");
}
e.printStackTrace();
} finally {
try {
if (stmt != null) {
stmt.close();
if (con != null) {
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
6.Create an xml for the bookstore. Validate the same using both DTD and XSD.
FIRSTt.xml
<book category="fiction">
<author>J.R.R. Tolkien</author>
<year>1954</year>
<price>25.00</price>
</book>
<title>Ender's Game</title>
<year>1985</year>
<price>18.99</price>
</book>
</bookstore>
BOOKSTORE.dtd
BOOKSTORE.XSD
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://mybookstore.com"
xmlns="http://mybookstore.com"
elementFormDefault="qualified">
<xs:element name="bookstore">
<xs:complexType>
<xs:sequence>
<xs:complexType>
<xs:sequence>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>