Node.js Manual for Web Development
Node.js Manual for Web Development
0 0 21
Course Objectives:
● To implement the static web pages using HTML and do client side validation usingJavaScript.
● To design and work with databases usingJava
● To develop an end to end application using java fullstack.
● To introduce Node JS implementation for server sideprogramming.
● To experiment with single page application development usingReact.
Course Outcomes: At the end of the course, the student will be able to,
● Build a custom website with HTML, CSS, and Bootstrap and littleJavaScript.
● Demonstrate Advanced features of JavaScript and learn aboutJDBC
● Develop Server – side implementation using Java technologieslike
● Develop the server – side implementation using NodeJS.
● Design a Single Page Application usingReact.
Exercises:
1. Build a responsive web application for shopping cart with registration, login,
catalog and cart pages using CSS3 features, flex andgrid.
2. Make the above web application responsive web application using Bootstrapframework.
3. UseJavaScriptfordoingclient–sidevalidation
ofthepagesimplementedinexperiment1and experiment2.
4. Explore the features of ES6 like arrow functions, callbacks, promises,
async/await. Implement an application for reading the weather information from
[Link] and display the information in the form of a graph on the
webpage.
5. Develop a java stand alone application that connects with the database (Oracle /
mySql) and perform the CRUD operation on the databasetables.
6. Create an xml for the bookstore. Validate the same using both DTD andXSD.
7. Design a controller with servlet that provides the interaction with application
developed in experiment 1 and the database created in experiment5.
8. Maintaining the transactional history of any user is very important. Explore the
various session tracking mechanism (Cookies, HTTPSession)
9. Create a custom server using http module and explore the other modules of Node
JS like OS, path,event.
10. Develop an express web application that can interact with REST API to perform
CRUD operations on student data. (UsePostman)
11. For the above application create authorized end points using JWT (JSON WebToken).
12. Create a react application for the student management system having registration,
login, contact, about pages and implement routing to navigate through thesepages.
13. Create a service in react that fetches the weather information from
[Link] and the display the current and historical weather information
using graphical representation using [Link]
14. Create a TODO application in react with necessary components and deploy it intogithub.
REFERENCE BOOKS:
1. Jon Duckett, Beginning HTML, XHTML, CSS, and JavaScript, Wrox Publications,2010
2. BryanBasham,KathySierraandBertBates,HeadFirstServletsandJSP,O’ReillyMedia,2nd
Edition,2008.
3. Vasan Subramanian, Pro MERN Stack, Full Stack Web App Development with
Mongo, Express, React, and Node, 2nd Edition, APress.
1. Build a response web application for shopping cart with registration cart with
registration ,login, catalog, and cart pages using CSS3 features, flex and grid.
Registration file
<!DOCTYPE html>
<html>
<head>
<title>Shopping Cart</title>
<link rel="stylesheet" href="[Link]">
</head>
<body>
<header>
<nav>
<ul>
<li><a href="[Link]">Catalog </a></li>
<li><a href="[Link]">Login</a></li>
<li><a href="[Link]">Register</a></li>
</ul>
</nav>
</header>
<main>
<section class="register-section">
<h2>Register</h2>
<form>
<input type="text" placeholder="Username" required>
<input type="email" placeholder="Email" required>
<input type="password" placeholder="Password" required>
<button type="submit">Register</button>
</form>
</section>
</main>
<script src="[Link]"></script>
</body>
</html
Login page
<!DOCTYPE html>
<html>
<head>
<title>Shopping Cart</title>
<link rel="stylesheet" href="[Link]">
</head>
<body>
<header>
<nav>
<ul>
<li><a href="[Link]">Catalog </a></li>
<li><a href="[Link]">Login</a></li>
<li><a href="[Link]">Register</a></li>
</ul>
</nav>
</header>
<main>
<section class="login-section">
<h2>Login</h2>
<form>
<input type="email" placeholder="Email" required>
<input type="password" placeholder="Password" required>
<button type="submit">Login</button>
</form>
</section>
</main>
<script src="[Link]"></script>
</body>
</html>
Index page
<!DOCTYPE html>
<html>
<head>
<title>Shopping Cart</title>
<link rel="stylesheet" href="[Link]">
</head>
<body>
<header>
<nav>
<ul>
<li><a href="[Link]">Catalog </a></li>
<li><a href="[Link]">Login</a></li>
<li><a href="[Link]">Register</a></li>
</ul>
</nav>
</header>
<main>
<section class="catalog">
<!-- Products will be dynamically generated here -->
</section>
<aside class="cart">
<h2>Shopping Cart</h2>
<div class="cart-items">
<!-- Cart items will be displayed here -->
</div>
<div class="cart-summary">
<p>Total: $<span id="totalAmount">0.00</span></p>
<button onclick="checkout()">Checkout</button>
</div>
</aside>
</main>
<script src="[Link]"></script>
</body>
</html>
Stylesheet page
[Link]
/* General styles */
body {
font-family: 'Arial', sans-serif;
margin: 0;
padding: 0;
background-color: #f5f5f5;
color: #333;
}
header {
background-color: #333;
color: #fff;
padding: 15px;
text-align: right;
}
nav ul {
list-style: none;
padding: 0;
margin: 0;
}
nav ul li {
display: inline;
margin-right: 20px;
}
nav ul li a {
color: #fff;
text-decoration: none;
}
/* Main content styles */
main {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
margin: 20px;
}
/* Catalog styles */
.catalog {
flex: 1 70%;
display: grid;
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
gap: 20px;
padding: 20px;
}
.product-card {
background-color: #fff;
padding: 15px;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
transition: transform 0.3s ease;
}
.product-card:hover {
transform: translateY(-5px);
}
.product-card h3 {
margin: 0;
font-size: 18px;
color: #333;
}
.product-card p {
margin-top: 10px;
font-size: 16px;
}
.product-card button {
display: block;
width: 100%;
padding: 8px 0;
margin-top: 10px;
color: #fff;
background-color: #333;
border: none;
border-radius: 3px;
cursor: pointer;
transition: background-color 0.3s;
}
.product-card button:hover {
background-color: #555;
}
/* Cart styles */
.cart {
flex: 1 30%;
background-color: #fff;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
padding: 20px;
}
.cart h2 {
margin-top: 0;
font-size: 24px;
color: #333;
}
.cart-items {
max-height: 400px;
overflow: auto;
}
.cart-summary {
margin-top: 20px;
text-align: right;
}
.cart-summary p {
font-size: 18px;
margin: 5px 0;
}
.cart-summary button {
padding: 10px 20px;
background-color: #333;
color: #fff;
border: none;
border-radius: 3px;
cursor: pointer;
transition: background-color 0.3s;
}
.cart-summary button:hover {
background-color: #555;
}
/* Responsive styles */
@media (max-width: 768px) {
main {
flex-direction: column;
}
.cart {
margin-top: 20px;
}
}
/* General styles */
body {
font-family: 'Arial', sans-serif;
margin: 0;
padding: 0;
background-color: #f5f5f5;
color: #333;
}
/* Header styles */
header {
background-color: #333;
color: #fff;
padding: 15px;
text-align: right;
}
nav ul {
list-style: none;
padding: 0;
margin: 0;
}
nav ul li {
display: inline;
margin-right: 20px;
}
nav ul li a {
color: #fff;
text-decoration: none;
}
/* Main content styles */
main {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
margin: 20px;
}
/* Login and Register Section styles */
.login-section,
.register-section {
flex: 1 45%;
background-color: #fff;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
padding: 20px;
margin-bottom: 20px;
}
h2 {
margin-top: 0;
font-size: 24px;
color: #333;
}
form {
display: flex;
flex-direction: column;
}
input {
padding: 10px;
margin: 8px 0;
border-radius: 3px;
border: 1px solid #ccc;
}
button {
padding: 10px;
background-color: #333;
color: #fff;
border: none;
border-radius: 3px;
cursor: pointer;
transition: background-color 0.3s;
}
button:hover {
background-color: #555;
}
[Link]
[Link](product => {
const productCard = [Link]('div');
[Link]('product-card');
[Link] = `
<h3>${[Link]}</h3>
<p>$${[Link]}</p>
<button onclick="addToCart(${[Link]})">Add to Cart</button>
`;
[Link](productCard);
});
}
let totalAmount = 0;
[Link](item => {
const cartItem = [Link]('div');
[Link] = `<p>${[Link]} - $${[Link]}</p>`;
[Link](cartItem);
totalAmount += [Link];
});
OUTPUT:
[Link]
<!DOCTYPE html>
<html>
<head>
<title>Shopping Cart</title>
<link rel="stylesheet"
href="[Link]
</head>
<body>
<header class="bg-dark">
<nav class="navbar navbar-expand navbar-dark">
<a class="navbar-brand mr-5" href="[Link]">Shopping Cart</a>
<a href="[Link]" class="btnbtn-light mr-5">Login</a>
<a href="[Link]" class="btnbtn-light mr-5">Register</a>
</nav>
</header>
<main class="container mt-4">
<section class="catalog row">
<!-- Products will be dynamically generated here -->
</section>
<aside class="cart bg-light p-3">
<h2>Shopping Cart</h2>
<div class="cart-items">
<!-- Cart items will be displayed here -->
</div>
<div class="cart-summary">
<p>Total: $<span id="totalAmount">0.00</span></p>
<button onclick="checkout()" class="btnbtn-dark">Checkout</button>
</div>
</aside>
</main>
<script src="[Link]"></script>
<script src="[Link]
</body>
</html>
Login [Link]
<!DOCTYPE html>
<html>
<head>
<title>Shopping Cart</title>
<link rel="stylesheet"
href="[Link]
<link rel="stylesheet" href="[Link]">
</head>
<body>
<header class="bg-dark">
<nav class="navbar navbar-expand navbar-dark">
<a class="navbar-brand mr-5" href="[Link]">Shopping Cart</a>
<a href="[Link]" class="btnbtn-light mr-5">Login</a>
<a href="[Link]" class="btnbtn-light mr-5">Register</a>
</nav>
</header>
<main class="container mt-4">
<section class="login-section bg-light p-3">
<h2>Login</h2>
<form>
<input type="email" placeholder="Email" required class="form-control">
<input type="password" placeholder="Password" required class="form-control">
<button type="submit" class="btnbtn-dark">Login</button>
</form>
</section>
</main>
<script src="[Link]
</body>
</html>
[Link]
<!DOCTYPE html>
<html>
<head>
<title>Shopping Cart</title>
<link rel="stylesheet"
href="[Link]
<link rel="stylesheet" href="[Link]">
</head>
<body>
<header class="bg-dark">
<nav class="navbar navbar-expand navbar-dark">
<a class="navbar-brand mr-5" href="[Link]">Shopping Cart</a>
<a href="[Link]" class="btnbtn-light mr-5">Login</a>
<a href="[Link]" class="btnbtn-light mr-5">Register</a>
</nav>
</header>
<main class="container mt-4">
<section class="login-section bg-light p-3">
<h2>Login</h2>
<form>
<input type="text" placeholder="Username" required class="form-control">
<input type="email" placeholder="Email" required class="form-control">
<input type="password" placeholder="Password" required class="form-control">
<button type="submit" class="btnbtn-dark">Login</button>
</form>
</section>
</main>
<script src="[Link]
</body>
</html>
[Link]
[Link]
<!DOCTYPE html>
<html>
<head>
<title>Shopping Cart</title>
<link rel="stylesheet" href="[Link]">
</head>
<body>
<header>
<nav>
<ul>
<li><a href="[Link]">Catalog </a></li>
<li><a href="[Link]">Login</a></li>
<li><a href="[Link]">Register</a></li>
</ul>
</nav>
</header>
<main>
<section class="register-section">
<h2>Register</h2>
<form id="registrationForm">
<input type="text" id="username" placeholder="Username" required>
<input type="email" id="email" placeholder="Email" required>
<input type="password" id="password" placeholder="Password" required>
<input type="text" id="fullName" placeholder="Full Name" required>
<button type="submit">Register</button>
</form>
</section>
</main>
<script>
// Mock data for products
const products = [
{ id: 1, name: "Product 1", price: 10.99 },
{ id: 2, name: "Product 2", price: 19.99 },
// Add more products as needed
];
[Link](product => {
const productCard = [Link]('div');
[Link]('product-card');
[Link] = `
<h3>${[Link]}</h3>
<p>$${[Link]}</p>
<button onclick="addToCart(${[Link]})">Add to Cart</button>
`;
[Link](productCard);
});
}
// Function to add items to the cart
function addToCart(productId) {
const selectedProduct = [Link](product => [Link] === productId);
[Link](item => {
const cartItem = [Link]('div');
[Link] = `<p>${[Link]} - $${[Link]}</p>`;
[Link](cartItem);
totalAmount += [Link];
});
const totalAmountDisplay = [Link]('totalAmount');
[Link] = [Link](2); // Update the total amount in the cart
}
// Function to handle the checkout process
function checkout() {
cart = []; // Clear the cart
updateCartDisplay();
alert('Thank you for your purchase!');
}
// Display the catalog when the page loads
[Link] = displayCatalog;
const form = [Link]('registrationForm');
[Link]('submit', function (event) {
[Link]();
if (validateForm()) {
// Submit the form
[Link]();
}
});
function validateForm() {
const username = [Link]('username').value;
const email = [Link]('email').value;
const password = [Link]('password').value;
const fullName = [Link]('fullName').value;
// Validation logic
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
const passwordRegex = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[0-9a-zA-Z]{8,}$/;
if ([Link]< 4) {
alert('Username must be at least 4 characters');
return false;
}
if () {
alert('Please enter a valid email address');
return false;
}
if () {
alert('Password must contain at least 8 characters, including one uppercase letter, one lowercase
letter, and one number');
return false;
}
if ([Link](' ').length< 2) {
alert('Please enter your full name');
return false;
}
return true;
}
</script>
</body>
</html>
[Link]
/* General styles */
body {
font-family: 'Arial', sans-serif;
margin: 0;
padding: 0;
background-color: #f5f5f5;
color: #333;
}
/* Header styles */
header {
background-color: #333;
color: #fff;
padding: 15px;
text-align: right;
}
nav ul {
list-style: none;
padding: 0;
margin: 0;
}
nav ul li {
display: inline;
margin-right: 20px;
}
nav ul li a {
color: #fff;
text-decoration: none;
}
/* Main content styles */
main {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
margin: 20px;
}
/* Catalog styles */
.catalog {
flex: 1 70%;
display: grid;
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
gap: 20px;
padding: 20px;
}
.product-card {
background-color: #fff;
padding: 15px;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
transition: transform 0.3s ease;
}
.product-card:hover {
transform: translateY(-5px);
}
.product-card h3 {
margin: 0;
font-size: 18px;
color: #333;
}
.product-card p {
margin-top: 10px;
font-size: 16px;
}
.product-card button {
display: block;
width: 100%;
padding: 8px 0;
margin-top: 10px;
color: #fff;
background-color: #333;
border: none;
border-radius: 3px;
cursor: pointer;
transition: background-color 0.3s;
}
.product-card button:hover {
background-color: #555;
}
/* Cart styles */
.cart {
flex: 1 30%;
background-color: #fff;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
padding: 20px;
}
.cart h2 {
margin-top: 0;
font-size: 24px;
color: #333;
}
.cart-items {
max-height: 400px;
overflow: auto;
}
.cart-summary {
margin-top: 20px;
text-align: right;
}
.cart-summary p {
font-size: 18px;
margin: 5px 0;
}
.cart-summary button {
padding: 10px 20px;
background-color: #333;
color: #fff;
border: none;
border-radius: 3px;
cursor: pointer;
transition: background-color 0.3s;
}
.cart-summary button:hover {
background-color: #555;
}
/* Responsive styles */
@media (max-width: 768px) {
main {
flex-direction: column;
}
.cart {
margin-top: 20px;
}
}
/* General styles */
body {
font-family: 'Arial', sans-serif;
margin: 0;
padding: 0;
background-color: #f5f5f5;
color: #333;
}
/* Header styles */
header {
background-color: #333;
color: #fff;
padding: 15px;
text-align: right;
}
nav ul {
list-style: none;
padding: 0;
margin: 0;
}
nav ul li {
display: inline;
margin-right: 20px;
}
nav ul li a {
color: #fff;
text-decoration: none;
}
h2 {
margin-top: 0;
font-size: 24px;
color: #333;
}
form {
display: flex;
flex-direction: column;
}
input {
padding: 10px;
margin: 8px 0;
border-radius: 3px;
border: 1px solid #ccc;
}
button {
padding: 10px;
background-color: #333;
color: #fff;
border: none;
border-radius: 3px;
cursor: pointer;
transition: background-color 0.3s;
}
button:hover {
background-color: #555;
}
[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Weather Graph</title>
<style>
body {
font-family: 'Arial', sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f4;
}
.container {
max-width: 800px;
margin: 20px auto;
text-align: center;
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h1 {
margin-bottom: 20px;
color: #333;
}
.weather-info {
display: flex;
flex-direction: column;
align-items: center;
}
.weather-details {
margin-bottom: 20px;
text-align: left;
}
#temperature,
#humidity {
font-weight: bold;
}
#weatherChart {
max-width: 100%;
margin-top: 20px;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
</style>
</head>
<body>
<div class="container">
<h1>Weather Graph</h1>
<div class="weather-info">
<div class="weather-details">
<p>City: <span id="city"></span></p>
<p>Temperature: <span id="temperature"></span>°C</p>
<p>Humidity: <span id="humidity"></span>%</p>
</div>
</div>
</div>
<script>
const city = 'Amangal';
const fetchWeatherData = async () => {
const apiKey = '55182a39ac895d7589769018264e680c';
try {
const response = await fetch(`[Link]
{city}&cnt=8&appid=${apiKey}&units=metric`);
const data = await [Link]();
return [Link](item => ({ date: item.dt_txt, temperature: [Link],
humidity: [Link] }));
} catch (error) {
[Link]('Error fetching weather data:', error);
}
};
const createWeatherGraph = async () => {
const weatherData = await fetchWeatherData();
if (weatherData) {
const dates = [Link](item =>[Link]);
const temperatures = [Link](item =>[Link]);
const humidity = [Link](item =>[Link]);
[Link]('temperature').innerText = temperatures[0];
[Link]('humidity').innerText = humidity[0];
[Link]('city').innerText = city;
}
};
createWeatherGraph();
</script>
</body>
</html>
5. Develop a java stand alone application that connects with the database
(Oracle / mySql) and perform the CRUD operation on the database tables.
MySQL Code:
Java Code
[Link]
import [Link].*;
import [Link];
String insertQuery = "INSERT INTO student VALUES(" + sid + ",'" + sname + "','" +
saddr + "')";
[Link](insertQuery);
Output:
Inserting Data into student table:
[Link]
import [Link].*;
import [Link];
Output :
Update Data in student table:
[Link]
import [Link].*;
import [Link];
Output :
Delete Data from student table:
[Link]
import [Link].*;
while ([Link]()) {
[Link]([Link]("s_id") + " \t " + [Link]("s_name") + " \t " +
[Link]("s_address"));
[Link](" ");
}
}
Output :
SID STU_NAME ADDRESS
6. Create an xml for the bookstore. Validate the same using both DTD
andXSD.
XML data to validate:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE bookstore[
<!ELEMENT bookstore (book+)>
<!ELEMENT book (title, author, price)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT price (#PCDATA)>
]>
<bookstore>
<book>
<title>Introduction to XML</title>
<author>John Doe</author>
<price>29.99</price>
</book>
<book>
<title>Programming with XML</title>
<author>Jane Smith</author>
<price>39.99</price>
</book>
</bookstore>
XML schema (XSD) data:
<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>
7. Design a controller with servlet that provides the interaction with application developed
inexperiment 1 and the database created in experiment 5.
Mysql database
Procedure:
[Link]:
<html>
<head>
<title> validation </title>
</head>
<body bgcolor="magenta">
<form action="[Link]" method="post">
<h1 align="center">REGISTRATION FORM</h1>
<table border="0">
<tr>
<td>Name:</td>
<td><input type="text" name="t1" min length="6"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="t2"></td>
</tr>
<tr>
<td>Phone number:</td>
<td><input type="text" name="t3"></td>
</tr>
<tr>
<td>E-mail id:</td>
<td><input type="text" name="t4"></td>
</tr>
<tr>
<td><input type="submit" value="submit"></td>
<td><input type="reset" value="cancel"></td>
</tr>
</table>
</form>
</body>
</html>
[Link]:
<%@ page language="java" import="[Link].*,[Link].*" %>
<html>
<form >
<%
String v1,v2,v3,v4,str;
v1=[Link]("t1");
v2=[Link]("t2");
v3=[Link]("t3");
v4=[Link]("t4");
try{
[Link]("[Link]");
Connection cn=[Link]("jdbc:odbc:oradsn","system","ravindra");
Statement st=[Link]();
[Link]("insert into register values('"+v1+"','"+v2+"',"+v3+",'"+v4+"')");
if(cn!=null)
{
%>
</form>
Registration Successful
<%
}
else
{
[Link]("Registration failed");
}
[Link]();
[Link]();
}catch(Exception e) { [Link](" Registration failed");
%>
<P><a href = "[Link]" target =f2 > <B> Back<B> </a>
<%
}
%>
</body></html>
Execution:
Create a table with name register with name (varchar2 (10)), password (varchar2 (10)),
Phone(number (10)) ,Email-ID (varchar2(10)).
Create the Data source name.
Start->settings->control panel->Administrative Tools->Data Sources.
Under SystemDSN add Microsoft ODBC for Oracle.
Set Data Source name to oradsn.
Output:
8. Maintaining the transactional history of any user is very important.
Explore the various session tracking mechanism (Cookies,
HTTPSession)
const express = require('express');
const cookieParser = require('cookie-parser');
const session = require('express-session');
const app = express();
// Cookie Parser middleware for handling cookies
[Link](cookieParser());
// Session middleware for managing server-side sessions
[Link](session({
secret: 'mysecret', // Change this to a secure value in production
resave: false,
saveUninitialized: true,
}));
[Link]('/set-cookie', (req, res) => {
// Setting a cookie
[Link]('userId', '12345', { maxAge: 900000, httpOnly: true });
[Link]('Cookie set successfully!');
});
[Link]('/get-cookie', (req, res) => {
// Getting the value of the cookie
const userId = [Link];
[Link](User ID from cookie: ${userId});
});
[Link]('/set-session', (req, res) => {
// Setting session data
[Link] = 'JohnDoe';
[Link]('Session set successfully!');
});
[Link]('/get-session', (req, res) => {
// Getting session data
const username = [Link] || 'No username set';
[Link](Username from session: ${username});
});
[Link](3001, () => {
[Link]('Server running on port 3001');
});
9. Create a custom server using http module and explore the other
modules of Node JS like OS, path,event.
const os = require('os');
// OS module information
const osInfo = `
<h1>OS Information</h1>
<p>Platform: ${[Link]()}</p>
<p>Architecture: ${[Link]()}</p>
`;
const pathInfo = `
<h1>Path Information</h1>
`;
[Link](`
<!DOCTYPE html>
<html>
<head>
<title>System Details</title>
</head>
<body>
${combinedInfo}
</body>
</html>
`);
} else {
});
[Link](PORT, () => {
[Link]([Link]());
// UPDATE a student by ID
[Link]('/students/:id', async (req, res) => {
try {
const{ id } = [Link];
const response = await [Link](`${apiUrl}/${id}`, [Link]);
[Link]([Link]);
} catch (error) {
[Link](500).json({ error: [Link] });
}
});
// DELETE a student by ID
[Link]('/students/:id', async (req, res) => {
try {
const{ id } = [Link];
const response = await [Link](`${apiUrl}/${id}`);
[Link]([Link]);
} catch (error) {
[Link](500).json({ error: [Link] });
}
});
[Link](PORT, () => {
[Link](`Server is running on port ${PORT}`);
});
//CODE ENDS//
node [Link]
---Enter---
-- Create Student --
{ "name": "NewStudent", "age": Number }
11. For the above application create authorized end points using JWT (JSON
WebToken).
// npmi express body-parser jsonwebtoken
// gedit [Link]
// node [Link]
const express = require('express');
const bodyParser = require('body-parser');
const jwt = require('jsonwebtoken');
// Login endpoint to generate JWT token (example - use your own logic for
authentication)[Link]('/login', (req, res) => { // In a real application, verify the
credentials const username = [Link]; const user = { username }; //
Example user const accessToken = [Link](user, secretKey);
[Link]({ accessToken });});const PORT = 3000; // You can use any available
[Link](PORT, () => { [Link]();});
Server is running on port ${PORT}
12. Create a react application for the student management system
having registration, login, contact, about pages and implement routing
to navigate through thesepages.
npm create vite@latest
./
React
JavaScript
npmi
npmi react-router-dom
delete [Link]
[Link]
[Link]
[Link]
.nav {
display: flex;
justify-content: space-between;
align-items: center;
padding: 20px;
background-color: #f5f5f5;
border-bottom: 1px solid #ccc;
}
.center-div {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
input{
padding: 10px;
margin: 10px;
border-radius: 5px;
border: 1px solid #ccc;
width: 300px;
font-size: 16px;
outline: none;
}
button{
padding: 10px;
margin: 10px;
border-radius: 5px;
border: 1px solid #ccc;
background-color: #f5f5f5;
font-size: 16px;
cursor: pointer;
}
//start
npm run dev
13. Create a service in react that fetches the weather information from
[Link] and the display the current and historical
weather information using graphical representation using [Link]
npm create vite@latest
.
React
javaScript
npmi
npm install axios [Link]
import React, { useState } from 'react';
import Chart from '[Link]/auto'; // Import [Link]
import './[Link]'; // Assuming you have a CSS file for styles
const WeatherApp = () => {
const [city, setCity] = useState('');
const [weatherData, setWeatherData] = useState(null);
const [error, setError] = useState(false);
const apiKey = "55182a39ac895d7589769018264e680c";
const apiUrl =
"[Link]
const checkWeather = async (city) => {
try {
const response = await fetch(apiUrl + city + `&appid=${apiKey}`);
if ([Link] === 404) {
setError(true);
setWeatherData(null);
} else {
const data = await [Link]();
setWeatherData(data);
setError(false);
drawGraph(data); // Draw the graph once data is fetched
}
} catch (error) {
[Link]('Error fetching data:', error);
}
};
const handleSearch = () => {
checkWeather(city);
};
const drawGraph = (data) => {
const ctx =
[Link]('weatherGraph').getContext('2d');
new Chart(ctx, {
type: 'bar',
data: {
labels: ['Temperature', 'Humidity', 'Wind Speed'],
datasets: [{
style={[Link]}
/>
<buttononClick={addTask} style={[Link]}>
{editIndex !== -1 ? 'Update' : 'Add Task'}
</button>
</div>
<ul style={[Link]}>
{[Link]((task, index) => (
<li key={index} style={{ ...[Link],
...([Link](index) && [Link]) }}>
<spanonClick={() => completeTask(index)} style={{ flexGrow:
'1', cursor: 'pointer' }}>
{task}
</span>
<buttononClick={() => editTask(index)}
style={[Link]}>
Edit
</button>
<buttononClick={() => completeTask(index)}
style={[Link]}>
{[Link](index) ?'Mark Incomplete' : 'Mark
Complete'}
</button>
<buttononClick={() => deleteTask(index)}
style={[Link]}>
Delete
</button>
</li>
))}
</ul>
</div>
);
};
export default App;