Full stack development Example code
Practical No. 1 Bootstrap example
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://getbootstrap.com/docs/5.3/assets/css/docs.css" rel="stylesheet">
<title>Bootstrap Example</title>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body class="p-3 m-0 border-0 bd-example m-0 border-0">
<div id="carouselExampleIndicators" class="carousel slide">
<div class="carousel-indicators">
<button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1"></button>
<button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="1" aria-label="Slide 2"></button>
<button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="2" aria-label="Slide 3"></button>
</div>
<div class="carousel-inner">
<div class="carousel-item active">
<svg class="bd-placeholder-img bd-placeholder-img-lg d-block w-100" width="500" height="400" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Placeholder: First slide" preserveAspectRatio="xMidYMid slice" focusable="false"><title>Placeholder</title><rect width="100%" height="100%" fill="#777"></rect><text x="50%" y="50%" fill="#555" dy=".3em">First slide</text></svg>
</div>
<div class="carousel-item">
<svg class="bd-placeholder-img bd-placeholder-img-lg d-block w-100" width="500" height="400" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Placeholder: Second slide" preserveAspectRatio="xMidYMid slice" focusable="false"><title>Placeholder</title><rect width="100%" height="100%" fill="#666"></rect><text x="50%" y="50%" fill="#444" dy=".3em">Second slide</text></svg>
</div>
<div class="carousel-item">
<svg class="bd-placeholder-img bd-placeholder-img-lg d-block w-100" width="500" height="400" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Placeholder: Third slide" preserveAspectRatio="xMidYMid slice" focusable="false"><title>Placeholder</title><rect width="100%" height="100%" fill="#555"></rect><text x="50%" y="50%" fill="#333" dy=".3em">Third slide</text></svg>
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
</body>
</html>
Practical No. 2 Bootstrap using Bradcrump
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://getbootstrap.com/docs/5.3/assets/css/docs.css" rel="stylesheet">
<title>Bootstrap Example</title>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body class="p-3 m-0 border-0 bd-example m-0 border-0">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item active" aria-current="page">Home</li>
</ol>
</nav>
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="#">Home</a></li>
<li class="breadcrumb-item active" aria-current="page">Library</li>
</ol>
</nav>
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="#">Home</a></li>
<li class="breadcrumb-item"><a href="#">Library</a></li>
<li class="breadcrumb-item active" aria-current="page">Data</li>
</ol>
</nav>
</body>
</html>
Practical No. 3
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="C:\Users\admin\Desktop\vipul\css\bootstrap.min.css">
<script src="C:\Users\admin\Desktop\vipul\js\bootstrap.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
</head>
<body>
<img src="download.png" alt="" width="100%">
<nav class="navbar navbar-expand-lg navbar-light bg-light ">
<div class="container-fluid">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#myNavbar" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-toggle" id="ddAboutUs" role="button" data-bs-toggle="dropdown" href="#" aria-expanded="false">About Us</a>
<ul class="dropdown-menu" aria-labelledby="ddAboutUs">
<li><a class="dropdown-item" href="#">About TCSC</a></li>
<li><a class="dropdown-item" href="#">Vision and Mission</a></li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link dropdown-toggle" id="ddAboutUs" role="button" data-bs-toggle="dropdown" href="#" aria-expanded="false">Alumni</a>
<ul class="dropdown-menu" aria-labelledby="ddAboutUs">
<li><a class="dropdown-item" href="#">Alumni Registration</a></li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact Us</a>
</li>
</ul>
</div>
</div>
</nav>
<script src="C:\Users\admin\Desktop\vipul\js\bootstrap.min.js"></script>
</body>
</html>
Practical No. 4 Shopping List app
<!DOCTYPE html>
<html ng-app="shoppingListApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
</head>
<body ng-controller="ShoppingListController as ctrl">
<h1>Shopping List</h1>
<form ng-submit="ctrl.addItem()">
<input type="text" ng-model="ctrl.newItem" placeholder="Add item" required>
<button type="submit">Add</button>
</form>
<ul>
<li ng-repeat="item in ctrl.items">
{{ item }}
<button ng-click="ctrl.removeItem(item)">Remove</button>
</li>
</ul>
</body>
</html>
<script>
angular.module('shoppingListApp', [])
.controller('ShoppingListController', function () {
var ctrl = this;
ctrl.items = [];
ctrl.newItem = '';
ctrl.addItem = function () {
if (ctrl.newItem !== '') {
ctrl.items.push(ctrl.newItem);
ctrl.newItem = '';
}
};
ctrl.removeItem = function (item) {
var index = ctrl.items.indexOf(item);
if (index !== -1) {
ctrl.items.splice(index, 1);
}
};
});
</script>
Practical no. 5 Cart application
<!DOCTYPE html>
<html ng-app="cartApp">
<head>
<title>Cart Application</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.8.2/angular.min.js"></script>
</head>
<body ng-controller="cartController">
<h1>Cart Application</h1>
<div ng-repeat="product in products">
<p>{{ product.name }} - ${{ product.price }}</p>
<button ng-click="addToCart(product)">Add to Cart</button>
</div>
<h2>Cart</h2>
<ol>
<li ng-repeat="item in cartItems">{{ item.name }} - ${{ item.price }}</li>
</ol>
<h3>Total: ${{ getTotal() }}</h3>
</body>
</html>
<script>
angular.module('cartApp', [])
.controller('cartController', function($scope) {
$scope.products = [
{ name: 'Product 1', price: 10 },
{ name: 'Product 2', price: 20 },
{ name: 'Product 3', price: 30 }
];
$scope.cartItems = [];
$scope.addToCart = function(product) {
$scope.cartItems.push(product);
};
$scope.getTotal = function() {
var total = 0;
for (var i = 0; i < $scope.cartItems.length; i++) {
total += $scope.cartItems[i].price;
}
return total;
};
});
</script>
\
Practical no.6 Translation app
<!DOCTYPE html>
<html ng-app="translationApp">
<head>
<title>Translation Application</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.8.2/angular.min.js"></script>
</head>
<body ng-controller="translationController">
<h1>Translation Application</h1>
<select ng-model="selectedLanguage">
<option ng-repeat="language in languages" value="{{ language.code }}">{{ language.name }}</option>
</select>
<div>
<h2>Selected Language: {{ selectedLanguage }}</h2>
<p>{{ translations[selectedLanguage] }}</p>
</div>
</body>
</html>
<script>
angular.module('translationApp', [])
.controller('translationController', function($scope) {
$scope.languages = [
{ name: 'English', code: 'en' },
{ name: 'japanese', code: 'jm' },
{ name: 'Marathi', code: 'mr' },
{ name: 'Hindi', code: 'hd' },
];
$scope.translations = {
'en': 'Hello!',
'jm': 'konchiwa!',
'mr': 'Namaskar!',
'hd':'Namaste!'
};
$scope.selectedLanguage = 'en';
});
</script>
Practical no. 7 angular js Form application
<!DOCTYPE html>
<html ng-app="formApp">
<head>
<title>AngularJS Form Application</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.8.2/angular.min.js"></script>
</head>
<body ng-controller="FormController">
<h1>AngularJS Form Application</h1>
<form ng-submit="submitForm()">
<label for="name">Name:</label>
<input type="text" id="name" ng-model="formData.name" ng-blur="validateName()" ng-focus="resetNameError()">
<span style="color: red;" ng-show="nameError">{{ nameError }}</span>
<br>
<label for="email">Email:</label>
<input type="email" id="email" ng-model="formData.email" ng-change="validateEmail()" ng-focus="resetEmailError()">
<span style="color: red;" ng-show="emailError">{{ emailError }}</span>
<br>
<button type="button" ng-click="clickEvent()">Click Me</button>
<br>
<button type="submit">Submit</button>
</form>
<script>
angular.module('formApp', [])
.controller('FormController', ['$scope', function($scope) {
$scope.formData = {};
$scope.clickEvent = function() {
console.log('Click event triggered.');
};
$scope.validateName = function() {
if (!$scope.formData.name) {
$scope.nameError = 'Name is required.';
} else {
$scope.nameError = '';
}
};
$scope.resetNameError = function() {
$scope.nameError = '';
};
$scope.validateEmail = function() {
if (!$scope.formData.email) {
$scope.emailError = 'Email is required.';
} else if (!/^\S+@\S+\.\S+$/.test($scope.formData.email)) {
$scope.emailError = 'Invalid email format.';
} else {
$scope.emailError = '';
}
};
$scope.resetEmailError = function() {
$scope.emailError = '';
};
$scope.submitForm = function() {
// Perform any additional logic or AJAX calls here if needed.
console.log('Form submitted:', $scope.formData);
};
}]);
</script>
</body>
</html>
Practical no. 8 Chat application
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Chat APP</title>
</head>
<body>
<h1>Chatting</h1>
<input type="text" id="message" placeholder="Enter Message" />
<button id="sendBtn">Send</button>
<div id="messages"></div>
<script src="/socket.io/socket.io.js"></script>
<script>
const socket = io();
const sendBtn = document.getElementById("sendBtn");
const messageInput = document.getElementById("message");
const allMessages = document.getElementById("messages");
socket.on("message", (message) => {
const p = document.createElement("p");
p.innerText = message;
allMessages.appendChild(p);
});
sendBtn.addEventListener("click", (e) => {
const message = messageInput.value;
console.log(message);
socket.emit("user-message", message);
});
</script>
</body>
</html>
PRACTICAL no. 9 Socket .io
const http = require("http");
const express = require("express");
const path = require("path");
const { Server } = require("socket.io");
const app = express();
const server = http.createServer(app);
const io = new Server(server);
// Socket.io
io.on("connection", (socket) => {
socket.on("user-message", (message) => {
io.emit("message", message);
});
});
app.use(express.static(path.resolve("./public")));
app.get("/", (req, res) => {
return res.sendFile("/public/index.html");
});
server.listen(9000, () => console.log(`Server Started at PORT:9000`));
const express = require('express')
const mongoose = require('mongoose')
const url = 'mongodb://localhost/AlienDBex'
const app = express()
mongoose.connect(url, {useNewUrlParser:true})
const con = mongoose.connection
con.on('open', () => {
console.log('connected...')
})
app.use(express.json())
const alienRouter = require('./routes/aliens')
app.use('/aliens',alienRouter)
app.listen(9000, () => {
console.log('Server started')
})
const mongoose = require('mongoose')
const alienSchema = new mongoose.Schema({
name: {
type: String,
required: true
},
tech: {
type: String,
required: true
},
sub: {
type: Boolean,
required: true,
default: false
}
})
module.exports = mongoose.model('Alien',alienSchema)
const express = require('express')
const router = express.Router()
const Alien = require('../models/alien')
router.get('/', async(req,res) => {
try{
const aliens = await Alien.find()
res.json(aliens)
}catch(err){
res.send('Error ' + err)
}
})
router.get('/:id', async(req,res) => {
try{
const alien = await Alien.findById(req.params.id)
res.json(alien)
}catch(err){
res.send('Error ' + err)
}
})
router.post('/', async(req,res) => {
const alien = new Alien({
name: req.body.name,
tech:
req.body.tech,
sub: req.body.sub
})
try{
const a1 = await alien.save()
res.json(a1)
}catch(err){
res.send('Error')
}
})
router.patch('/:id',async(req,res)=> {
try{
const alien = await Alien.findById(req.params.id)
alien.sub = req.body.sub
const a1 = await alien.save()
res.json(a1)
}catch(err){
res.send('Error')
}
})
module.exports = router
Comments
Post a Comment