Node JS
Node JS
Solution :
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="./style.css">
<title>Home - FBS</title>
</head>
<body>
<div class="wrapper">
<div class="container">
<header>
<table width="100%" align="center" cellpadding="0"
cellspacing="2">
<tr>
<th width="20%"><img src="fbs.png" alt="FBS LOGO"
width="130" height="100"/></th>
<th colspan=4>
<h1 style="color:white;">FBS - WORLD BEST ONLINE
EBOOKS WEBSITE</h1>
</th>
</tr>
</table>
</header>
<nav>
<table width="100%" align="center" cellpadding="0"
cellspacing="2">
<tbody align="center" style="font-weight:bold;font-
size:18px;"">
<tr>
<td width="20%"><hr><a
href="index.html">Home</a><hr></td>
<td width="20%"><hr><a
href="login.html">Login</a><hr></td>
<td width="20%"><hr><a
href="registration.html">Registration</a><hr></td>
<td width="20%"><hr><a href="cart.html"
>Cart</a><hr></td>
</tr>
</tbody>
</table>
</nav>
</div>
<div class="container1">
<div class="sidebar1"></div>
<div class="container2">
<main>
<center>
<h2>Welcome to FBS e-Book's Website</h2>
<p>Shopping at <font size=5>FBS</font> can be
both <font size=5>fun</font>
and <font size=5>savings</font>.</br>Shop with
us in this special <font
size=5>discount</font> season and save upto
<font size=5>90%</font> on all your
purchases.</br></p>
<br/><br/><br/><br/><br/><br/><br/><br/>
</main>
</div>
<div class="sidebar2"></div>
</div>
<footer><font color="white">(C) 2024 All rights reserved by
FBS ebooks</font></footer>
</div>
</body>
</html>
login.html
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="./style.css">
<title>Login - FBS</title>
</head>
<body>
<div class="wrapper">
<div class="container">
<header>
<table width="100%" align="center" cellpadding="0"
cellspacing="2">
<tr>
<th width="20%"><img src="fbs.png" alt="FBS LOGO"
width="130" height="100"/></th>
<th colspan=4>
<h1 style="color:white;">FBS - WORLD BEST ONLINE
EBOOKS WEBSITE</h1>
</th>
</tr>
</table>
</header>
<nav>
<table width="100%" align="center" cellpadding="0"
cellspacing="2">
<tbody align="center" style="font-weight:bold;font-
size:18px;"">
<tr>
<td width="20%"><hr><a
href="index.html">Home</a><hr></td>
<td width="20%"><hr><a
href="login.html">Login</a><hr></td>
<td width="20%"><hr><a
href="registration.html">Registration</a><hr></td>
<td width="20%"><hr><a href="cart.html"
>Cart</a><hr></td>
</tr>
</tbody>
</table>
</nav>
</div>
<div class="container1">
<div class="sidebar1"></div>
<div class="container2">
<main>
<center><br>
<h3> Login Details</h3> <br/>
<form name="f1">
<table width="100%" align="center" >
<tr>
<td> User Name : </td>
<td> <input type="text"
name="username"></td>
</tr>
<tr><td><br></td></tr>
<tr>
<td> Password : </td>
<td> <input type="password"
name="password"></td>
</tr>
<tr><td><br></td></tr>
<tr><td></td>
<td><input type="submit" value="SUBMIT">
<input type="reset" value="RESET"></td>
</tr>
</table>
</form>
</center>
</main>
</div>
<div class="sidebar2"></div>
</div>
<footer><font color="white">(C) 2024 All rights reserved by
FBS ebooks</font></footer>
</div>
</body>
</html>
registration.html
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="./style.css">
<title>Registration - FBS</title>
</head>
<body>
<div class="wrapper">
<div class="container">
<header>
<table width="100%" align="center" cellpadding="0"
cellspacing="2">
<tr>
<th width="20%"><img src="fbs.png" alt="FBS LOGO"
width="130" height="100"/></th>
<th colspan=4>
<h1 style="color:white;">FBS - WORLD BEST ONLINE
EBOOKS WEBSITE</h1>
</th>
</tr>
</table>
</header>
<nav>
<table width="100%" align="center" cellpadding="0"
cellspacing="2">
<tbody align="center" style="font-weight:bold;font-
size:18px;"">
<tr>
<td width="20%"><hr><a
href="index.html">Home</a><hr></td>
<td width="20%"><hr><a
href="login.html">Login</a><hr></td>
<td width="20%"><hr><a
href="registration.html">Registration</a><hr></td>
<td width="20%"><hr><a href="cart.html"
>Cart</a><hr></td>
</tr>
</tbody>
</table>
</nav>
</div>
<div class="container1">
<div class="sidebar1"></div>
<div class="container2">
<main>
<center><br>
<h3>Registration Form </h3>
<br/>
<form name="f1">
<table cellpadding="1" align="center" >
<tr><td> Name:*</td>
<td><input type="text"
name="username"></td></tr>
<tr><td>Password:*</td>
<td><input type="password"
name="password"></td></tr>
<tr><td>Email ID:*</td>
<td><input type="text" name="email"></td></tr>
<tr><td>Phone Number:*</td>
<td><input type="text" name="phno"></td></tr>
<tr><td valign="top">Gender:*</td>
<td><input type="radio" name="radio"
value="1">Male
<input type="radio" name="radio"
value="2">Female</td></tr>
<tr> <td valign="top">Language Known:*</td>
<td> <input type="checkbox" name="checkbox"
value="English">English<br/>
<input type="checkbox" name="checkbox"
value="Telugu">Telugu<br>
<input type="checkbox" name="checkbox"
value="Hindi">Hindi<br>
<input type="checkbox" name="checkbox"
value="Tamil">Tamil
</td></tr>
<tr> <td valign="top">Address:*</td>
<td><textarea name="address"></textarea></td>
<tr><td></td><td><input type="submit"
value="submit" hspace="10">
<input type="reset" value="reset"></td></tr>
<tr> <td colspan=2 >*<font
color="#FF0000">fields are mandatory</font>
</td>
</tr>
</table>
</form>
</center>
</main>
</div>
<div class="sidebar2"></div>
</div>
<footer><font color="white">(C) 2024 All rights reserved by
FBS ebooks</font></footer>
</div>
</body>
</html>
cart.html
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="./style.css">
<title>Cart - FBS</title>
</head>
<body>
<div class="wrapper">
<div class="container">
<header>
<table width="100%" align="center" cellpadding="0"
cellspacing="2">
<tr>
<th width="20%"><img src="fbs.png" alt="FBS LOGO"
width="130" height="100"/></th>
<th colspan=4>
<h1 style="color:white;">FBS - WORLD BEST ONLINE
EBOOKS WEBSITE</h1>
</th>
</tr>
</table>
</header>
<nav>
<table width="100%" align="center" cellpadding="0"
cellspacing="2">
<tbody align="center" style="font-weight:bold;font-
size:18px;"">
<tr>
<td width="20%"><hr><a
href="index.html">Home</a><hr></td>
<td width="20%"><hr><a
href="login.html">Login</a><hr></td>
<td width="20%"><hr><a
href="registration.html">Registration</a><hr></td>
<td width="20%"><hr><a href="cart.html"
>Cart</a><hr></td>
</tr>
</tbody>
</table>
</nav>
</div>
<div class="container1">
<div class="sidebar1"></div>
<div class="container2">
<main>
<center>
<h3>Cart</h3>
<table width="100%" align="center" >
<tbody>
<tr>
<th width="40%"><hr>BookName<hr></th>
<th width="20%"><hr>Price<hr></th>
<th width="20%"><hr>Quantity<hr></th>
<th width="20%"><hr>Amount<hr></th> </tr>
</tbody>
<tbody align=center>
<tr> <td>Java Programming </td>
<td>Rs. 2300/-</td>
<td>2</td>
<td>Rs. 4600/-</td></tr>
<tr><td>Web Technologies</td>
<td>Rs. 3000/-</td>
<td>1</td>
<td>Rs. 3000/-</td></tr>
<tr><td></td>
<td><hr><font color="#996600">Total
Amount:</font><hr></td>
<td><hr>3<hr></td>
<td><hr>Rs. 7600/-<hr></td> </tr>
</tbody>
</table>
</center>
</main>
</div>
<div class="sidebar2"></div>
</div>
<footer><font color="white">(C) 2024 All rights reserved by
FBS ebooks</font></footer>
</div>
</body>
</html>
style.css
body{
font-family: monospace;
}
main {
background-color: #efefef;
color: #330000;
margin-left: 10px;
height: 60vh;
}
header, footer {
background-color: #000d57;
color: #fff;
padding: 1rem;
height: 50px;
}
header, nav{
margin-bottom: 10px;
flex-basis: 50%;
}
footer{
margin-top: 10px;
}
nav {
background-color: #fff;
color: #000;
padding: 1rem;
height: 20px;
}
.sidebar1, .sidebar2 {
flex-basis: 10%;
background-color: #fff;
color: #000;
}
.sidebar2{
margin-left: 10px;
}
.container1{
display: flex;
}
.container2 {
display: flex;
flex-direction: column;
flex: 1;
}
.wrapper {
display: flex;
flex-direction: column;
font-weight: 600;
}
Output :
2. Use JavaScript for doing client – side validation of the
pages implemented in the experiment
Solution :
registrationJS.html
<html>
<head>
<title> Welcome to NNRG e-Book's website</title>
<script language="javascript">
function validate() {
// username validation
var uname = f1.username.value;
if (uname.length<=0)
{
alert("Please Enter UserName");
f1.username.focus();
return false;
}
if (uname.length < 8)
{
alert("Please enter UserName not less than 8");
f1.username.focus();
return false;
}
//password validation
var pwd = f1.password.value;
if (pwd.length<=0)
{
alert("Please Enter password");
f1.password.focus();
return false;
}
if (pwd.length < 6)
{
alert("Please enter Password not less than 6");
f1.password.focus();
return false;
}
// email validation
var email = f1.email.value;
if (email.length<=0)
{
alert("Please Enter email");
f1.email.focus();
return false;
}
else {
let eflag=false;
for(i=0;i<email.length;i++) {
if(email.charAt(i)=="@")
{
eflag=true;
}
}
if(!(eflag))
{
alert("Please enter a valid Email ID");
f1.email.focus();
return false;
}
}
// phone number validation
var phno = f1.phno.value;
if (phno.length<=0)
{
alert("Please Enter Phone Number");
f1.phno.focus();
return false;
}
if (isNaN(phno))
{
alert("Please Enter Valid Phone Number");
f1.phno.focus();
return false;
}
if (phno.length != 10)
{
alert("Please Enter Valid Phone Number");
f1.phno.focus();
return false;
}
// gender validation
let flag=false;
for(i=0;i<f1.gen.length;i++)
if(f1.gen[i].checked)
flag=true;
if(!(flag))
{
alert("Please choose a Gender");
return false;
}
// Language validation
flag=false;
for(i=0;i<f1.lang.length;i++)
if(f1.lang[i].checked)
flag=true;
if(!(flag))
{
alert("Please select at least one of the Language options.");
return false;
}
// address validation
var addr = f1.address.value;
if (addr.length<=0)
{
alert("Please Enter address");
f1.address.focus();
return false;
}
// to display Success message
alert("Registration Successful");
}
</script>
</head>
<body>
<center><br>
<h3>Registration Form </h3>
<br/>
<form name="f1">
<table cellpadding="1" align="center" >
<tr><td> User Name:*</td>
<td><input type="text" name="username"></td></tr>
<tr><td>Password:*</td>
<td><input type="password" name="password"></td></tr>
<tr><td>Email ID:*</td>
<td><input type="text" name="email"></td></tr>
<tr><td>Phone Number:*</td>
<td><input type="text" name="phno"></td></tr>
<tr><td valign="top">Gender:*</td>
<td><input type="radio" name="gen" value="Male">Male
<input type="radio" name="gen" value="Female">Female</td></tr>
<tr> <td valign="top">Language Known:*</td>
<td> <input type="checkbox" name="lang"
value="English">English<br/>
<input type="checkbox" name="lang" value="Telugu">Telugu<br>
<input type="checkbox" name="lang" value="Hindi">Hindi<br>
<input type="checkbox" name="lang" value="Tamil">Tamil
</td></tr>
<tr> <td valign="top">Address:*</td>
<td><textarea name="address"></textarea></td>
<tr><td></td><td><input type="button" value="SUBMIT" hspace="10"
onclick="validate()">
<input type="reset" value="RESET"></td></tr>
<tr> <td colspan=2 >*<font color="#FF0000">fields are
mandatory</font>
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
Output :
3. 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.
Solution :
server.js
// server.js
constexpress = require('express');
constaxios = require('axios');
constapp = express();
constport = 3000;
app.use(express.static('public'));
try {
constapiKey = 'c97c0c1086d42990e89d64d76f50bb61';
constresponse =
awaitaxios.get(`https://api.openweathermap.org/data/2.5/weather?q=$
{city}&appid=${apiKey}`);
consttemperature = response.data.main.temp;
res.json({ temperature });
} catch (error) {
console.error('Error fetching weather data:', error);
res.status(500).json({ error:'Internal Server Error' });
}
});
app.listen(port, () => {
console.log(`Server listening at http://localhost:${port}`);
});
☛ Create a folder named public and create an index.html file for the
frontend:
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="./style.css">
<title>Home - FBS</title>
</head>
<body>
<div class="wrapper">
<div class="container">
<header>
<table width="100%" align="center" cellpadding="0"
cellspacing="2">
<tr>
<th width="20%"><img src="fbs.png" alt="FBS LOGO"
width="130" height="100"/></th>
<th colspan=4>
<h1 style="color:white;">FBS - WORLD BEST ONLINE
EBOOKS WEBSITE</h1>
</th>
</tr>
</table>
</header>
<nav>
<table width="100%" align="center" cellpadding="0"
cellspacing="2">
<tbody align="center" style="font-weight:bold;font-
size:18px;"">
<tr>
<td width="20%"><hr><a
href="index.html">Home</a><hr></td>
<td width="20%"><hr><a
href="login.html">Login</a><hr></td>
<td width="20%"><hr><a
href="registration.html">Registration</a><hr></td>
<td width="20%"><hr><a href="cart.html"
>Cart</a><hr></td>
</tr>
</tbody>
</table>
</nav>
</div>
<div class="container1">
<div class="sidebar1"></div>
<div class="container2">
<main>
<center>
<h2>Welcome to FBS e-Book's Website</h2>
<p>Shopping at <font size=5>FBS</font> can be
both <font size=5>fun</font>
and <font size=5>savings</font>.</br>Shop with
us in this special <font
size=5>discount</font> season and save upto
<font size=5>90%</font> on all your
purchases.</br></p>
<br/><br/><br/><br/><br/><br/><br/><br/>
</main>
</div>
<div class="sidebar2"></div>
</div>
<footer><font color="white">(C) 2024 All rights reserved by
FBS ebooks</font></footer>
</div>
</body>
</html>
node server.js
3. From the dashboard, locate my API Keys section and click on "Create
Key" or "API Keys" to generate a new API key.
4. Provide a name for your API key (e.g., "WeatherApp") and click on
the "Generate" or "Create" button.
5. Your API key will be generated and displayed on the screen. Make sure
to copy it as we will need it later.
Output :
☛ Locate API key
Solution :
I will provide you with the MySQL code for creating the student table and make some
changes to your Java code to improve it:
☛ MySQL Code:
This SQL code creates a table with three columns: s_id for student ID (primary key),
s_name for student name, and s_address for student address.
Java Code
InsertData.java
import java.sql.*;
import java.util.Scanner;
System.out.println("________________________________________");
Output :
UpdateData.java
import java.sql.*;
import java.util.Scanner;
System.out.println("________________________________________");
Output :
DeleteData.java
import java.sql.*;
import java.util.Scanner;
System.out.println("________________________________________");
DisplayData.java
import java.sql.*;
System.out.println("________________________________________");
while (rs.next()) {
System.out.println(rs.getString("s_id") + " \t " +
rs.getString("s_name") + " \t " + rs.getString("s_address"));
System.out.println("________________________________________");
}
}
Solution :
bookstore.xml
bookstore.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://example.com"
xmlns="http://example.com">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="bookstore" type="bookstoreType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="bookstoreType">
<xs:sequence>
<xs:element name="book" type="bookType" minOccurs="0"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="bookType">
<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:complexType>
</xs:schema>
Solution :
Execute the server script using the Node.js runtime. In the terminal, run:
node server.js
This will start the HTTP server, and you should see the message "Server running at
http://127.0.0.1:3000/".
☛ Check OS Information:
In the same terminal where your server is running, you'll see information about your
operating system (OS) type, platform, architecture, CPU cores, etc.
The script emits a custom event and listens for it. In the terminal, you should see the
message "Custom Event Triggered: { message: 'Hello from custom event!' }".
To stop the server, press Ctrl+C in the terminal where the server is running.
server.js
Output :
In the Terminal:
In the Browser:
Link: http://127.0.0.1:3000/
7. Develop an express web application that can interact with
REST API to perform CRUD operations on student data. (Use
Postman)
Solution :
Firstly we need to create a new folder and open the folder in the
command prompt and enter a command as below:
npminit -y
db.js
module.exports = { initializeDatabase };
when we execute both the db.js then the database will be created that
is mydatabase.db
app.js
const express = require('express');
const sqlite3 = require('sqlite3');
const{ initializeDatabase } = require('./db');
const app = express();
const port = 3000;
// Update a student
app.put('/students/:id', (req, res) => {
const id = req.params.id;
const{ name, age, grade } = req.body;
db.run('UPDATE students SET name = ?, age = ?, grade = ? WHERE id
= ?', [name, age, grade, id], function (err) {
if (err) {
return console.error(err.message);
}
res.json({ updatedID:id });
});
});
// Delete a student
app.delete('/students/:id', (req, res) => {
const id = req.params.id;
db.run('DELETE FROM students WHERE id = ?', id, function (err) {
if (err) {
return console.error(err.message);
}
res.json({ deletedID:id });
});
});
app.listen(port, () => {
console.log('Server running at http://localhost:${port}');
});
Output :
GET:
Open Postman.
Set the request type to GET.
Enter the URL: http://localhost:3000/students.
Open Postman.
Set the request type to POST.
Enter the URL: http://localhost:3000/students.
Go to the "Body" tab.
Select raw and set the body to JSON format.
GET: #all Students
Solution :
From the dashboard, locate my API Keys section and click on "Create
Key" or "API Keys" to generate a new API key.
Provide a name for your API key (e.g., "WeatherApp") and click on the
"Generate" or "Create" button.
Your API key will be generated and displayed on the screen. Make sure
to copy it as we will need it later.
Locate API key
Step 2: Set up a new React project
npxcreate-react-app weather-app
cd weather-app
In the project directory, install the necessary packages by executing the following
command
We will use the Axios library to make HTTP requests to the OpenWeatherMap API.
Inside the "src" directory, create a new file called "Weather.js" and
open it in your code editor.
useEffect(() => {
fetchData();
}, []);
return (
<div>
<form onSubmit={handleSubmit}>
<input
type="text"
placeholder="Enter city name"
value={city}
onChange={handleInputChange}
/>
<button type="submit">Get Weather</button>
</form>
{weatherData ? (
<>
<h2>{weatherData.name}</h2>
<p>Temperature: {weatherData.main.temp} C</p>
<p>Description: {weatherData.weather[0].description}</p>
<p>Feels like : {weatherData.main.feels_like} C</p>
<p>Humidity : {weatherData.main.humidity}%</p>
<p>Pressure : {weatherData.main.pressure}</p>
<p>Wind Speed : {weatherData.wind.speed}m/s</p>
</>
) : (
<p>Loading weather data...</p>
)}
</div>
);
};
Replace {YOUR_API_KEY} in the API URL with the API key you generated from
OpenWeatherMap.
Output :
Initial Screen
After Supply the City name
9. Create a TODO application in react with necessary
components and deploy it into github.
Solution :
Our first task is to set up the React project. This step involves creating the necessary
project structure. Here's how you can do it:
Open your terminal and navigate to your preferred directory. Run the following
command to generate a new React app. Replace "todo-app" with your desired project
name:
This command will create a directory named "todo-app" with all the initial code required
for a React app.
cd todo-app
npm start
This will open your React app, and you�ll see the default React starter page in your
web browser at 'http://localhost:3000'.
Step 2: Create the App Component
In this step, we create the App component, which serves as the entry point to our Todo
List application.
src->Component
Now, let's create the 'TodoList' component, which is responsible for managing the list of
tasks and handling task-related functionality.
function TodoList() {
const [tasks, setTasks] = useState([
{
id: 1,
text: 'Doctor Appointment',
completed: true
},
{
id: 2,
text: 'Meeting at School',
completed: false
}
]);
src->Component
In this step, we create the 'TodoItem' component, which represents an individual task in
our Todo List.
return (
<div className="todo-item">
<input
type="checkbox"
checked={task.completed}
onChange={handleChange}
/>
<p>{task.text}</p>
<button onClick={() => deleteTask(task.id)}>
X
</button>
</div>
);
}
exportdefault TodoItem;
These three components, 'App', 'TodoList', and 'TodoItem', work together to create a
functional Todo List application in React. The 'TodoList' component manages the state
of the tasks, and the 'TodoItem' component represents and handles individual tasks
within the list.
Step 5: Styling
To enhance the visual appeal of your Todo List, you can apply some basic styling.
Here�s an example of how you can style the todo items. In the `App.css` file, add the
following styles:
.todo-item {
display: flex;
justify-content: space-between;
margin-bottom: 8px;
}
.todo-itemp {
color: #888;
text-decoration: line-through;
}
Output :
Initially it looks like:
Next,