Nodejs
Nodejs
e-mail: [email protected]
Dept of CSE
Page 1
NODEJS Lab
e-mail: [email protected]
The educational environment in order to develop graduates with the strong academic technical backgrounds
needed to achieve distinction in the discipline and to bring up the Institution as an Institution of Academic
excellence of International standard.
MISSION
We transform persons into personalities by the state-of-the-art infrastructure, time consciousness, quick response
and the best academic practices through assessment and advice.
CORE VALUES
Attaining global eminence, by achieving excellence in all that we do in life education and service
Dept of CSE
Page 2
NODEJS Lab
The educational environment in order to develop graduates with the strong academic technical
backgrounds needed to achieve distinction in the discipline and to bring up the Institution as an
Institution of Academic excellence of International standard.
MISSION
We transform persons into personalities by the state-of-the-art infrastructure, time consciousness, quic
Dept of CSE
Page 3
NODEJS Lab
PEO1: Graduates will demonstrate technical skills, competency in AI & ML and exhibit team
management capability with proper communication in a job environment
PEO2: Graduates will function in their profession with social awareness and responsibility
PEO3: Graduates will interact with their peers in other disciplines in industry and
society and contribute to the economic growth of the country
PO2: Problem analysis: Identify, formulate, review research literature and analyze
complex engineering problems reaching substantiated conclusions using first principles
of mathematics, natural sciences, and engineering sciences.
PO5: Modern tool usage: Create, select, and apply appropriate techniques, resources,
and modern engineering and IT tools including prediction and modeling to complex
engineering activities with an understanding of the limitations.
PO6: The engineer and society: Apply reasoning informed by the contextual knowledge to
assess societal, health, safety, legal and cultural issues and the consequent responsibilities
relevant to the professional engineering practice.
Dept of CSE
Page 4
NODEJS Lab
PO7: Environment and sustainability: Understand the impact of the professional engineering
solutions in societal and environmental contexts, and demonstrate the knowledge of, and
need for sustainable development.
PO8: Ethics: Apply ethical principles and commit to professional ethics and
responsibilities and norms of the engineering practice.
PO9: Individual and team work: Function effectively as an individual and as a member
or leader in diverse teams, and in multidisciplinary settings.
PO10: Communication: Communicate effectively on complex engineering activities with the
engineering community and with society at large, such as, being able to comprehend
and write effective reports and design documentation, make effective presentations, and give
and receive clear instructions.
PO12: Life-long learning: Recognize the need for, and have the preparation and ability to
engage in independent and life-long learning in the broadest context of technological
change.
PSO1: Design and develop intelligent automated systems applying mathematical, analytical,
programming and operational skills to solve real world problems
PSO3: Implement engineering solutions for the benefit of society by the use of AI and ML
Dept of CSE
Page 5
NODEJS Lab
Code L T P
NODE JS/ REACT JS/ DJANGO LAB
Credits: 1 0 0 2
Course Objectives:
To implement the static web pages using HTML and do client side validation
using JavaScript.
To design and work with databases using Java
To develop an end to end application using java full stack.
To introduce Node JS implementation for server side programming.
To experiment with single page application development using React.
Exercises:
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 Bootstrap
framework.
3. Use JavaScript for doing client – side validation of the pages implemented in
Dept of CSE
Page 6
NODEJS Lab
Dept of CSE
Page 7
NODEJS Lab
For the above application create authorized end points using JWT (JSON Web Token).
11. Create a react application for the student management system having
registration, login, contact, about pages and implement routing to navigate
through these pages.
12. Create a service in react that fetches the weather information from
openweathermap.org and the display the current and historical weather
information using graphical representation usingchart.js
13. Create a TODO application in react with necessary components and deploy it
into github.
Course Outcomes:
At the end of the course, the student will be able to,
Build a custom website with HTML, CSS, and Bootstrap and little JavaScript.
Demonstrate Advanced features of JavaScript and learn about JDBC
Develop Server – side implementation using Java technologies like
Develop the server – side implementation using Node JS.
Design a Single Page Application using React.
Reference Books:
1. Jon Duckett, Beginning HTML, XHTML, CSS, and JavaScript, Wrox Publications, 2010
2. Bryan Basham, Kathy Sierra and Bert Bates, Head First Servlets and JSP,
O’Reilly Media, 2ndEdition, 2008.
3. Vasan Subramanian, Pro MERN Stack, Full Stack Web App Development
with Mongo, Express, React, and Node, 2nd Edition, A Press.
Dept of CSE
Page 8
NODEJS Lab
1.Build a responsive web application for shopping cart with registration, login,
catalog and cart pages using CSS3 features, flex and grid.
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">
Dept of CSE
Page 9
NODEJS Lab
<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>
Dept of CSE
Page 10
NODEJS Lab
Dept of CSE
Page 11
NODEJS Lab
</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>
Dept of CSE
Page 12
NODEJS Lab
Dept of CSE
Page 13
NODEJS Lab
<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>
Dept of CSE
Page 14
NODEJS Lab
</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>
Dept of CSE
Page 15
NODEJS Lab
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;
}
Dept of CSE
Page 16
NODEJS Lab
.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 :
Dept of CSE
Page 17
NODEJS Lab
Dept of CSE
Page 18
NODEJS Lab
Dept of CSE
Page 19
NODEJS Lab
3.Use JavaScript for doing client – side validation of the pages implemented in the
experiment
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();
Dept of CSE
Page 20
NODEJS Lab
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;
}
}
Dept of CSE
Page 21
NODEJS Lab
Dept of CSE
Page 22
NODEJS Lab
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>
Dept of CSE
Page 23
NODEJS Lab
Output :
Dept of CSE
Page 24
NODEJS Lab
Dept of CSE
Page 25
NODEJS Lab
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.
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}`);
});
Dept of CSE
Page 26
NODEJS Lab
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>
Dept of CSE
Page 27
NODEJS Lab
node server.js
Output :
Dept of CSE
Page 28
NODEJS Lab
Dept of CSE
Page 29
NODEJS Lab
5. Develop a java stand alone application that connects with the database (Oracle / mySql)
and perform the CRUD operation on the database tables.
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:
sql> CREATE TABLE IF NOT EXISTS student ( s_id INT PRIMARY KEY,
s_nameVARCHAR(255), s_addressVARCHAR(255) );
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;
String insertQuery = "INSERT INTO student VALUES(" + sid + ",'" + sname + "','" +
saddr + "')";
s.executeUpdate(insertQuery);
Dept of CSE
Page 30
NODEJS Lab
Output :
UpdateData.java
import java.sql.*;
import java.util.Scanner;
Dept of CSE
Page 31
NODEJS Lab
Output :
DeleteData.java
import java.sql.*;
import java.util.Scanner;
Dept of CSE
Page 32
NODEJS Lab
Output :
DisplayData.java
import java.sql.*;
while (rs.next()) {
System.out.println(rs.getString("s_id") + " \t " + rs.getString("s_name") + " \t " +
rs.getString("s_address"));
System.out.println("________________________________________");
}
}
Dept of CSE
Page 33
NODEJS Lab
Output :
6. Create an xml for the bookstore. Validate the same using both DTD and XSD.
Solution :
bookstore.xml
Dept of CSE
Page 34
NODEJS Lab
<author>Jane Smith</author>
<price>39.99</price>
</book>
</bookstore>
bookstore.xsd
<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>
Dept of CSE
Page 35
NODEJS Lab
Output :
9. Create a custom server using http module and explore the other modules of Node JS
like OS, path, event.
Solution :
Open a terminal or command prompt in the directory where you saved your server.js file.
Execute the server script using the Node.js runtime. In the terminal, run:
Dept of CSE
Page 36
NODEJS Lab
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 joined path using the path module is printed in the terminal.
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
Dept of CSE
Page 37
NODEJS Lab
Output :
In the Terminal:
Dept of CSE
Page 38
NODEJS Lab
In the Browser:
Link: http://127.0.0.1:3000/
10. Develop an express web application that can interact with REST API to perform CRUD
operations on student data. (Use Postman)
Firstly we need to create a new folder and open the folder in the command prompt and
enter a command as below:
npminit -y
Dept of CSE
Page 39
NODEJS Lab
db.js
Dept of CSE
Page 40
NODEJS Lab
console.error(err.message);
} else {
console.log('The students table has been created or already exists.');
}
});
}
module.exports = { initializeDatabase };
when we execute both the db.js then the database will be created that is mydatabase.db
app.js
Dept of CSE
Page 41
NODEJS Lab
res.json(rows);
});
});
// 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) {
Dept of CSE
Page 42
NODEJS Lab
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.
Dept of CSE
Page 43
NODEJS Lab
Dept of CSE
Page 44
NODEJS Lab
DELETE:
Dept of CSE
Page 45
NODEJS Lab
PUT:
Dept of CSE
Page 46
NODEJS Lab
13. Create a service in react that fetches the weather information from open weathermap.org
and the display the current and historical weather information using graphical representation
using chart.js
Dept of CSE
Page 47
NODEJS Lab
npxcreate-react-app weather-app
cd weather-app
In the project directory, install the necessary packages by executing the following command
Dept of CSE
Page 48
NODEJS Lab
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.
Add the following code to define a functional component named Weather:
useEffect(() => {
fetchData();
}, []);
Dept of CSE
Page 49
NODEJS Lab
};
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>
);
};
Dept of CSE
Page 50
NODEJS Lab
exportdefault App;
Your output should look like this:
Output :
Initial Screen
Dept of CSE
Page 51
NODEJS Lab
14. Create a TODO application in react with necessary components and deploy it into github.
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:
Dept of CSE
Page 52
NODEJS Lab
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'.
In this step, we create the App component, which serves as the entry point to our Todo List
application.
Dept of CSE
Page 53
NODEJS Lab
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
}
]);
Dept of CSE
Page 54
NODEJS Lab
<div className="todo-list">
{tasks.map(task => (
<TodoItem
key={task.id}
task={task}
deleteTask={deleteTask}
toggleCompleted={toggleCompleted}
/>
))}
<input
value={text}
onChange={e => setText(e.target.value)}
/>
<button onClick={() => addTask(text)}>Add</button>
</div>
);
}
exportdefault TodoList;
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>
Dept of CSE
Page 55
NODEJS Lab
);
}
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;
}
Your output should look like this:
Output :
Dept of CSE
Page 56
NODEJS Lab
Next,
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
Dept of CSE
Page 57
NODEJS Lab
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/
bootstrap.min.css" rel="stylesheet">
<style>
body {
font-family: monospace;
header,
footer {
background-color: #000d57;
color: white;
padding: 1rem;
footer {
margin-top: 10px;
.main-content {
background-color: #efefef;
color: #330000;
Dept of CSE
Page 58
NODEJS Lab
padding: 20px;
.sidebar {
background-color: #fff;
padding: 10px;
</style>
</head>
<body>
<div class="wrapper">
<header>
</div>
</header>
Dept of CSE
Page 59
NODEJS Lab
<nav class="bg-light">
<div class="container">
<li class="nav-item">
</li>
<li class="nav-item">
</li>
<li class="nav-item">
</li>
<li class="nav-item">
</li>
</ul>
</div>
</nav>
Dept of CSE
Page 60
NODEJS Lab
</div>
</div>
<div class="container">
<form>
<div class="mb-3">
</div>
<div class="mb-3">
</div>
</div>
Dept of CSE
Page 61
NODEJS Lab
</form>
</div>
</div>
<div class="container">
<form>
<div class="mb-3">
</div>
<div class="mb-3">
</div>
<div class="mb-3">
</div>
<div class="mb-3">
Dept of CSE
Page 62
NODEJS Lab
</div>
<div class="mb-3">
<label class="form-label">Gender</label><br>
</div>
<div class="mb-3">
</div>
<div class="mb-3">
</div>
</div>
Dept of CSE
Page 63
NODEJS Lab
</form>
</div>
</div>
<div class="container">
<h3 class="text-center">Cart</h3>
<thead>
<tr>
<th>Book Name</th>
<th>Price</th>
<th>Quantity</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
<tr>
<td>Java Programming</td>
<td>Rs. 2300/-</td>
<td>2</td>
<td>Rs. 4600/-</td>
Dept of CSE
Page 64
NODEJS Lab
</tr>
<tr>
<td>Web Technologies</td>
<td>Rs. 3000/-</td>
<td>1</td>
<td>Rs. 3000/-</td>
</tr>
<tr>
<td><strong>Rs. 7600/-</strong></td>
</tr>
</tbody>
</table>
</div>
</div>
<footer class="text-center">
</footer>
</div>
Dept of CSE
Page 65
NODEJS Lab
<script
src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"></script>
</body>
</html>
Dept of CSE
Page 66
NODEJS Lab
Output:
Dept of CSE
Page 67