web_tech_lab-10_140 (1)
web_tech_lab-10_140 (1)
Lab-10
Name: Rohan Mittal
Name :Samant saini Class: 5C
class:5c
roll no:2200290110140 Roll-no: 2200290110137
Code :
// Middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(session({
secret: "shopping-cart-secret",
resave: false,
saveUninitialized: true,
}));
// Sample products
const products = [
{ id: 1, name: "Laptop", price: 1000 },
{ id: 2, name: "Smartphone", price: 700 },
{ id: 3, name: "Headphones", price: 100 },
];
// Routes
app.get("/products", (req, res) => {
res.json(products);
});
if (!req.session.cart) {
req.session.cart = [];
}
app.listen(PORT, () => {
console.log(`Server is running on
http://localhost:${PORT}`);
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-
width, initial-scale=1.0">
<title>Shopping Cart</title>
<style>
body { font-family: Arial, sans-serif; padding: 20px; }
.product { margin: 10px 0; }
.cart { margin-top: 20px; }
.cart-item { margin: 5px 0; }
</style>
</head>
<body>
<h1>Shopping Cart</h1>
<h2>Available Products</h2>
<div id="products"></div>
<h2>Your Cart</h2>
<div id="cart"></div>
<script src="script.js"></script>
</body>
</html>
body {
font-family: Arial, sans-serif;
padding: 20px;
}
h1, h2 {
color: #333;
}
button {
padding: 5px 10px;
margin-left: 10px;
cursor: pointer;
}
.cart-item {
margin: 5px 0;
}
Output:
Your Cart:
Laptop - $1000 [Remove]
Smartphone - $700 [Remove]
Your Cart:
Smartphone - $700 [Remove]