Full Stack Development
Full Stack Development
Experiments:
- Defining routes
---
Features Covered
| Feature | Example |
|--------------------|--------------------------------|
express-routing-demo/
├── [Link]
└── [Link]
```json
"name": "express-routing-demo",
"version": "1.0.0",
"main": "[Link]",
"scripts": {
},
"dependencies": {
"express": "^4.18.2"
}
2. `[Link]` – Full Working Express App
```javascript
next();
});
// Root route
[Link](`
<ul>
<li><a href="/about">About</a></li>
<li>
<form action="/submit" method="POST">
<button type="submit">Submit</button>
</form>
</li>
</ul>
`);
});
// About page
});
});
});
// POST route example
[Link](`/greet?name=${encodeURIComponent(username)}`);
});
[Link](`<h1>Hello, ${name}!</h1>`);
});
[Link](PORT, () => {
});
```
---
How to Run:
1. Install dependencies:
```bash
```
```bash
node [Link]
```
- [[Link]
| URL | Description |
|------------------------------------|----------------------------------------|
Program:
|-------------|---------------|---------------------------|
File: `[Link]`:
```js
// In-memory "database"
let id = 1;
<html>
<head>
<title>Simple CRUD</title>
<style>
.container { max-width: 500px; margin: auto; background: white; padding: 20px; border-radius: 8px;
box-shadow: 0 0 10px rgba(0,0,0,0.1); }
li { padding: 10px; border-bottom: 1px solid #eee; display: flex; justify-content: space-between; }
input[type="text"] { width: 100%; padding: 10px; margin-top: 10px; border: 1px solid #ccc; border-
radius: 4px; }
button { background: crimson; color: white; border: none; padding: 5px 10px; border-radius: 4px;
cursor: pointer; }
</style>
</head>
<body>
<div class="container">
${content}
</div>
</body>
</html>`;
<h1>My Items</h1>
${list}
</form>
`);
[Link](html);
});
// Add item
[Link]('/');
});
// Delete item
[Link]('/');
});
// Start server
[Link](PORT, () => {
});
How to Run
3. Install Express:
```bash
npm init -y
``
bash
node [Link]
5. Open in browser:
- [[Link]
1.c. Write a program to show the working of middleware.
Program:
[Link]([Link]());
[Link](`
<h1>Send Data</h1>
<button type="submit">Submit</button>
</form>
`);
});
// POST route
[Link]({
message: "Data received successfully!",
payload: data
});
});
// Start server
[Link](PORT, () => {
});
Output:
2. ExpressJS – Templating, Form Data
Folder Structure:
Experiment_2/a/
├── views/
│ └── [Link]
├── [Link]
1. `[Link]`:
```js
});
});
// Start server
[Link](PORT, () => {
});
``
2. `views/[Link]`
```html
<!DOCTYPE html>
<html lang="en">
<head>
<style>
body {
padding: 20px;
background-color: #f4f4f4;
.container {
max-width: 500px;
margin: auto;
background: white;
padding: 30px;
border-radius: 10px;
text-align: center;
h1 {
color: #333;
}
input[type="text"] {
width: 100%;
padding: 10px;
margin-top: 10px;
border-radius: 5px;
font-size: 16px;
button {
margin-top: 10px;
background-color: #007BFF;
color: white;
border: none;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
button:hover {
background-color: #0056b3;
p{
font-size: 20px;
color: #333;
</style>
</head>
<body>
<div class="container">
<h1>Welcome!</h1>
<button type="submit">Submit</button>
</form>
<% } %>
</div>
</body>
</html>
`
How to Run:
```
```
```bash
``
```bash
node [Link]
``
4. Open browser:
- [[Link]
2. ExpressJS – Templating, Form Data
| Feature | Description |
|----------------------|-------------|
Folder Structure
```
form-data-demo/
├── views/
│ └── [Link]
├── [Link]
└── [Link]
```bash
npm init -y
```
Then install dependencies:
```bash
```
2. `views/[Link]`:
Create a folder named `views`, and inside it create a file called `[Link]`:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<style>
.container {
max-width: 500px;
margin: auto;
background: white;
padding: 20px;
border-radius: 8px;
text-align: center;
}
input[type="text"], input[type="email"] {
width: 100%;
padding: 10px;
margin: 10px 0;
border-radius: 4px;
button {
background-color: #007BFF;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
.output {
margin-top: 20px;
background: #e9ecef;
padding: 15px;
border-radius: 8px;
</style>
</head>
<body>
<div class="container">
<h1>User Registration</h1>
<div class="output">
</div>
<% } %>
<button type="submit">Submit</button>
</form>
</div>
</body>
</html>
```
---
## 3. `[Link]` – Full Working Code
```js
});
});
// Start server
[Link](PORT, () => {
});
How to Run:
2. Install dependencies:
```bash
```
```bash
node [Link]
```
4. Open in browser:
- [[Link]
3. ExpressJS – Cookies, Sessions, Authentication
Program:
Features Covered:
| Feature | Description |
|---------------------|-------------|
Folder Structure:
session-auth-demo/
├── views/
│ ├── [Link]
│ └── [Link]
├── [Link]
└── [Link]
```
1. Install Dependencies:
```bash
npm init -y
``
2. `views/[Link]`:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Login</title>
<style>
.container {
max-width: 400px;
margin: auto;
background: white;
padding: 20px;
border-radius: 8px;
text-align: center;
}
input[type="text"], input[type="password"] {
width: 100%;
padding: 10px;
margin: 10px 0;
border-radius: 4px;
button {
background-color: #007BFF;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
</style>
</head>
<body>
<div class="container">
<h2>Login</h2>
</form>
</div>
</body>
</html>
``
3. `views/[Link]`
```html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Dashboard</title>
<style>
.container {
max-width: 400px;
margin: auto;
background: white;
padding: 20px;
border-radius: 8px;
text-align: center;
}
a{
display: inline-block;
margin-top: 20px;
color: #007BFF;
text-decoration: none;
</style>
</head>
<body>
<div class="container">
<a href="/logout">Logout</a>
</div>
</body>
</html>
```
---
```js
const express = require('express');
const session = require('express-session');
const path = require('path');
// Routes
// Handle login
[Link]('/login', (req, res) => {
const { username, password } = [Link];
[Link]('Invalid credentials!');
});
// Logout
[Link]('/logout', (req, res) => {
[Link]((err) => {
if (err) {
return [Link]('/dashboard');
}
[Link]('/login');
});
});
// Start server
[Link](PORT, () => {
[Link](`Server running at [Link]
});
```
How to Run
2. Install dependencies:
```bash
```
```bash
node [Link]
```
4. Open in browser:
- [[Link]
3. ExpressJS – Cookies, Sessions, Authentication
- Sessions (`express-session`)
- Protected routes
This example is great for learning how to handle user authentication in Express without any
external libraries beyond `express` and `express-session`.
Features Covered
| Feature | Description |
|---------------------|-------------|
Folder Structure
auth-demo/
├── views/
│ ├── [Link]
│ └── [Link]
├── [Link]
└── [Link]
```
1. Install Dependencies
```bash
npm init -y
```
2. `views/[Link]`
```html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Login</title>
<style>
.container {
max-width: 400px;
margin: auto;
background: white;
padding: 20px;
border-radius: 8px;
input[type="text"], input[type="password"] {
width: 100%;
padding: 10px;
margin: 10px 0;
border-radius: 4px;
button {
background-color: #007BFF;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
.error {
color: red;
margin-bottom: 10px;
</style>
</head>
<body>
<div class="container">
<h2>Login</h2>
<% } %>
<button type="submit">Login</button>
</form>
</div>
</body>
</html>
```
3. `views/[Link]`
```html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Dashboard</title>
<style>
max-width: 400px;
margin: auto;
background: white;
padding: 20px;
border-radius: 8px;
text-align: center;
a{
display: inline-block;
margin-top: 20px;
color: #007BFF;
text-decoration: none;
</style>
</head>
<body>
<div class="container">
<a href="/logout">Logout</a>
</div>
</body>
</html>
```
```js
[Link](session({
secret: 'your-secret-key',
resave: false,
saveUninitialized: true,
cookie: { secure: false } // Use true if HTTPS is enabled
}));
const users = [
];
[Link]('/login');
});
});
// Handle login
const user = [Link](u => [Link] === username && [Link] === password);
if (user) {
return [Link]('/dashboard');
// If invalid credentials
});
if (![Link]) {
return [Link]('/login');
});
// Logout
[Link]((err) => {
if (err) {
return [Link]('/dashboard');
}
[Link]('/login');
});
});
// Start server
[Link](PORT, () => {
});
``
How to Run
2. Install dependencies:
```bash
``
```bash
node [Link]
```
4. Open browser:
- [[Link]
4. ExpressJS – Database, RESTful APIs.
[Link]
Program:
Features:
- JSON-based API
Folder Structure:
express-mongo-crud/
├── models/
│ └── [Link]
├── [Link]
├── [Link]
└── .env
```
1. Install Dependencies
```bash
npm init -y
``
2. `.env` File
```env
PORT=3000
MONGO_URI=mongodb://localhost:27017/admin
```
```js
// models/[Link]
name: {
type: String,
required: true
},
price: {
type: Number,
required: true
},
description: {
type: String
```
```js
// [Link]
require('dotenv').config();
[Link]([Link]());
[Link](cors());
[Link](helmet());
[Link](morgan('dev'));
// MongoDB Connection
[Link]([Link].MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true
})
// Root Route
[Link]({ message: 'Welcome to the Product CRUD API!', documentation: 'Use /api/products'
});
});
// Routes
try {
await [Link]();
[Link](201).json(product);
} catch (err) {
});
try {
[Link](products);
} catch (err) {
});
try {
const product = await [Link]([Link]);
[Link](product);
} catch (err) {
});
try {
[Link],
);
[Link](updated);
} catch (err) {
});
// Delete Product - DELETE /api/products/:id
try {
} catch (err) {
});
// Start Server
[Link](PORT, () => {
});
```
Output:
4. ExpressJS – Database, RESTful APIs
Folder Structure:
```
todo-spa/
├── public/
│ └── [Link]
├── models/
│ └── [Link]
├── [Link]
├── [Link]
└── .env
```
```env
PORT=3000
MONGO_URI=mongodb://localhost:27017/admin
```
```js
// models/[Link]
task: {
type: String,
required: true
},
completed: {
type: Boolean,
default: false
```
```html
<!DOCTYPE html>
<html lang="en">
<head>
<style>
body { font-family: Arial; padding: 20px; background: #f4f4f4; }
.container { max-width: 500px; margin: auto; background: white; padding: 20px; border-
radius: 8px; box-shadow: 0 0 10px rgba(0,0,0,0.1); }
input[type="text"] { width: 100%; padding: 10px; margin-bottom: 10px; border: 1px solid
#ccc; border-radius: 4px; }
button { padding: 10px 15px; background-color: #007BFF; color: white; border: none; border-
radius: 4px; cursor: pointer; }
li { padding: 10px; border-bottom: 1px solid #eee; display: flex; justify-content: space-
between; align-items: center; }
</style>
</head>
<body>
<div class="container">
<ul id="taskList"></ul>
</div>
<script>
try {
const res = await fetch(API_URL);
[Link] = '';
[Link](todo => {
const li = [Link]('li');
[Link] = `
<div>
<button onclick="deleteTask('${todo._id}')">🚀</button>
</div>
`;
[Link](li);
});
} catch (err) {
if (!task) return;
try {
method: 'POST',
});
[Link] = '';
fetchTasks();
} catch (err) {
try {
method: 'PUT',
});
fetchTasks();
} catch (err) {
try {
method: 'DELETE'
});
fetchTasks();
} catch (err) {
}
[Link] = () => {
fetchTasks();
};
</script>
</body>
</html>
```
```js
// [Link]
require('dotenv').config();
// Middleware
[Link]([Link]());
[Link](cors());
[Link](morgan('dev'));
// MongoDB Connection
[Link]([Link].MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true
})
// Routes
try {
[Link](todos);
} catch (err) {
});
// Create Todo
try {
await [Link]();
[Link](201).json(newTodo);
} catch (err) {
});
// Update Todo by ID
try {
[Link],
[Link],
);
[Link](updated);
} catch (err) {
});
// Delete Todo by ID
try {
} catch (err) {
});
[Link](__dirname + '/public/[Link]');
});
// Start Server
[Link](PORT, () => {
});
```
How to Run:
1. Install dependencies:
```bash
```
```bash
mongod
```
3. Start server:
```bash
node [Link]
``
4. Open browser:
```
[Link]
```
Output:
5. ReactJS – Render HTML, JSX, Components – function & Class
Here is the working ReactJS + Webpack setup with all required files for rendering a simple
HTML element using React.
Folder Structure:
```
react-hello/
├── [Link]
├── [Link]
├── [Link]
├── [Link]
1. `[Link]`
```json
"name": "react-hello",
"version": "1.0.0",
"scripts": {
"start": "webpack-dev-server"
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"webpack": "^5.74.0",
"webpack-cli": "^5.0.0",
"webpack-dev-server": "^4.11.1",
"babel-loader": "^9.1.2",
"@babel/core": "^7.22.11",
"@babel/preset-env": "^7.22.10",
"@babel/preset-react": "^7.22.5"
``
2. `[Link]`
```html
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<div id="root"></div>
</body>
</html>
```
3. `[Link]`
```js
return (
);
};
[Link](<App />);
4. `[Link]`:
```js
entry: './[Link]',
output: {
filename: '[Link]',
clean: true,
},
devServer: {
static: './',
hot: true,
open: true
},
module: {
rules: [
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
}
}
},
resolve: {
};
```
How to Run:
```bash
npm init -y
```
```bash
npm start
```
Output in Browser:
You’ll see:
Hello, React!
5. ReactJS – Render HTML, JSX, Components – function & Class
Folder Structure
```
react-app/
├── src/
│ └── [Link]
├── [Link]
├── [Link]
└── .babelrc
```
1. `[Link]`
```json
"name": "react-app-no-html",
"version": "1.0.0",
"scripts": {
"start": "webpack-dev-server"
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"webpack": "^5.74.0",
"webpack-cli": "^5.0.0",
"webpack-dev-server": "^4.11.1",
"babel-loader": "^9.1.2",
"@babel/core": "^7.22.11",
"@babel/preset-env": "^7.22.10",
"@babel/preset-react": "^7.22.5",
"html-webpack-plugin": "^5.5.3",
"webpack-dev-server": "^4.11.1"
```
2. `.babelrc`
```json
```
```js
return (
<h1>Hello, JSX!</h1>
</div>
);
[Link](<App />);
4. `[Link]`
```js
[Link] = {
mode: 'development',
entry: './src/[Link]',
output: {
filename: '[Link]',
clean: true,
},
devServer: {
static: './dist',
hot: true,
open: true
},
module: {
rules: [
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
},
plugins: [
new HtmlWebpackPlugin({
templateContent: `
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<div id="root"></div>
</body>
</html>
`,
inject: true
})
],
resolve: {
};
```
How to Run
```bash
npm init -y
```
npm start
```
Output:
5. ReactJS – Render HTML, JSX, Components – function & Class
c. Write a program for creating and nesting components (function and class).
Program:
This example uses modern React syntax (with JSX), and includes all necessary setup
instructions.
Folder Structure
react-component-demo/
│
├── src/
│ └── [Link]
│
├── [Link]
├── [Link]
└── .babelrc
1. [Link]
{
"name": "react-component-demo",
"version": "1.0.0",
"scripts": {
"start": "webpack-dev-server"
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"webpack": "^5.74.0",
"webpack-cli": "^5.0.0",
"webpack-dev-server": "^4.11.1",
"babel-loader": "^9.1.2",
"@babel/core": "^7.22.11",
"@babel/preset-env": "^7.22.10",
"@babel/preset-react": "^7.22.5",
"html-webpack-plugin": "^5.5.3"
}
}
2. .babelrc
{
"presets": ["@babel/preset-env", "@babel/preset-react"]
}
// Functional Component
function Header() {
return (
<header>
<h1>React Component Demo</h1>
</header>
);
}
// Class Component
class Content extends [Link] {
render() {
return (
<main>
<Greeting />
<Features />
</main>
);
}
}
// Render to DOM
const root = [Link]([Link]('root'));
[Link](<App />);
[Link] = {
mode: 'development',
entry: './src/[Link]',
output: {
filename: '[Link]',
path: [Link](__dirname, 'dist'),
clean: true
},
devServer: {
static: './dist',
hot: true,
open: true
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
}
]
},
plugins: [
new HtmlWebpackPlugin({
templateContent: `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>React Component Nesting</title>
</head>
<body>
<div id="root"></div>
</body>
</html>
`,
inject: true
})
],
resolve: {
extensions: ['.js', '.jsx']
}
};
How to Run
1. Initialize project
npm init -y
2. Install dependencies
[Link]
Output:
6. ReactJS – Props and States, Styles, Respond to Events
Program:
Folder Structure
react-props-state/
│
├── src/
│ └── [Link]
│
├── [Link]
├── [Link]
└── .babelrc
1. [Link]
{
"name": "react-props-state",
"version": "1.0.0",
"scripts": {
"start": "webpack-dev-server"
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"webpack": "^5.74.0",
"webpack-cli": "^5.0.0",
"webpack-dev-server": "^4.11.1",
"babel-loader": "^9.1.2",
"@babel/core": "^7.22.11",
"@babel/preset-env": "^7.22.10",
"@babel/preset-react": "^7.22.5",
"html-webpack-plugin": "^5.5.3"
}
}
2. .babelrc
{
"presets": ["@babel/preset-env", "@babel/preset-react"]
}
return (
<div>
<p>You clicked <strong>{count}</strong> times</p>
<button onClick={increment}>Click Me</button>
</div>
);
}
// Render to DOM
const root = [Link]([Link]('root'));
[Link](<App />);
4. [Link] – Webpack Setup
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
[Link] = {
mode: 'development',
entry: './src/[Link]',
output: {
filename: '[Link]',
path: [Link](__dirname, 'dist'),
clean: true
},
devServer: {
static: './dist',
hot: true,
open: true
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
}
]
},
plugins: [
new HtmlWebpackPlugin({
templateContent: `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>React Props & State Demo</title>
</head>
<body>
<div id="root"></div>
</body>
</html>
`,
inject: true
})
],
resolve: {
extensions: ['.js', '.jsx']
}
};
How to Run
npm init -y
npm install react react-dom
npm install --save-dev webpack webpack-cli babel-loader @babel/core @babel/preset-env
@babel/preset-react html-webpack-plugin webpack-dev-server
[Link]
You’ll see:
Hello, Alice!
You clicked 0 times
[Click Me]
Each time you click the button, the counter increases — demonstrating state management.
Output:
[Link] – Props and States, Styles, Respond to Events .
b. Write a program to add styles (CSS & Sass Styling) and display data.
Program:
Handling events
This example includes everything you need to run a complete React app with Webpack,
Babel, and CSS styling — all in one post.
Folder Structure:
react-props-state-css/
│
├── src/
│ └── [Link]
│ └── [Link]
│
├── [Link]
├── [Link]
└── .babelrc
1. [Link]
{
"name": "react-props-state-css",
"version": "1.0.0",
"scripts": {
"start": "webpack-dev-server"
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"webpack": "^5.74.0",
"webpack-cli": "^5.0.0",
"webpack-dev-server": "^4.11.1",
"babel-loader": "^9.1.2",
"@babel/core": "^7.22.11",
"@babel/preset-env": "^7.22.10",
"@babel/preset-react": "^7.22.5",
"html-webpack-plugin": "^5.5.3",
"css-loader": "^6.7.3",
"style-loader": "^3.3.2",
"webpack-dev-server": "^4.11.1"
}
}
2. .babelrc
{
"presets": ["@babel/preset-env", "@babel/preset-react"]
}
3. src/[Link] – React Code with Props, State, Events
import React, { useState } from 'react';
import ReactDOM from 'react-dom/client';
import './[Link]';
return (
<div className="counter">
<p>You clicked <strong>{count}</strong> times</p>
<button onClick={increment} className="btn">Click Me</button>
</div>
);
}
.app-container {
max-width: 600px;
margin: 50px auto;
background: white;
padding: 30px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
text-align: center;
}
.greeting {
color: #007BFF;
margin-bottom: 20px;
}
.counter {
margin-top: 20px;
}
.btn {
padding: 10px 20px;
background-color: #28a745;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
}
.btn:hover {
background-color: #218838;
}
[Link] = {
mode: 'development',
entry: './src/[Link]',
output: {
filename: '[Link]',
path: [Link](__dirname, 'dist'),
clean: true
}, devServer: {
static: './dist',
hot: true,
open: true
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader']
}
]
},
plugins: [
new HtmlWebpackPlugin({
templateContent: `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>React Props & State with CSS</title>
</head>
<body>
<div id="root"></div>
</body>
</html>
`,
inject: true
})
],
resolve: {
extensions: ['.js', '.jsx']
}
};
How to Run
1. Initialize project
npm init -y
2. Install dependencies
npm start
[Link]
Output:
[Link] – Props and States, Styles, Respond to Events.
c. Write a program for responding to events.
Program:
This version includes all fixes and optimizations based on the knowledge base, including setting
mode: 'development' in Webpack for better debugging.
Folder Structure
react-event-app/
│
├── src/
│ ├── [Link]
│ └── [Link]
│
├── [Link]
├── [Link]
└── .babelrc
1. [Link]
{
"name": "react-event-app",
"version": "1.0.0",
"scripts": {
"start": "webpack-dev-server"
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"webpack": "^5.74.0",
"webpack-cli": "^5.0.0",
"webpack-dev-server": "^4.11.1",
"babel-loader": "^9.1.2",
"@babel/core": "^7.22.11",
"@babel/preset-env": "^7.22.10",
"@babel/preset-react": "^7.22.5",
"html-webpack-plugin": "^5.5.3",
"css-loader": "^6.7.3",
"style-loader": "^3.3.2"
}
}
2. .babelrc
{
"presets": ["@babel/preset-env", "@babel/preset-react"]
}
3. src/[Link] – React Code with Event Handling
import React, { useState } from 'react';
import ReactDOM from 'react-dom/client';
import './[Link]';
function App() {
const [count, setCount] = useState(0);
const [message, setMessage] = useState('');
const [inputValue, setInputValue] = useState('');
return (
<div className="app-container">
<h1>React Event Handling Demo</h1>
<hr />
<hr />
// Render to DOM
const root = [Link]([Link]('root'));
[Link](<App />);
4. src/[Link] – Styling
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
}
.app-container {
max-width: 600px;
margin: 50px auto;
background: white;
padding: 30px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
text-align: center;
}
.btn {
padding: 10px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s ease;
}
.btn:hover {
background-color: #0056b3;
}
.input-field {
padding: 10px;
width: 250px;
margin-top: 10px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 16px;
}
h2 {
color: #333;
}
p{
margin-top: 10px;
font-size: 16px;
}
[Link] = {
mode: 'development', // 🚀 From knowledge base: improves debugging
entry: './src/[Link]',
output: {
filename: '[Link]',
path: [Link](__dirname, 'dist'),
clean: true,
},
devServer: {
static: './dist',
hot: true,
open: true
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader']
}
]
},
plugins: [
new HtmlWebpackPlugin({
templateContent: `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>React Event Handling</title>
</head>
<body>
<div id="root"></div>
</body>
</html>
`,
inject: true
})
],
resolve: {
extensions: ['.js', '.jsx']
}
};
How to Run
1. Initialize and install dependencies
npm init -y
npm install react react-dom
npm install --save-dev webpack webpack-cli babel-loader @babel/core @babel/preset-env
@babel/preset-react html-webpack-plugin css-loader style-loader webpack-dev-server
npm start
Webpack Dev Server will open your app at:
[Link]
Output:
7. ReactJS – Conditional Rendering, Rendering Lists, React Forms
Program:
complete and working ReactJS program that demonstrates conditional rendering, using:
Functional components
useState hook
JSX syntax
Folder Structure
react-conditional-rendering/
│
├── src/
│ └── [Link]
│
├── [Link]
├── [Link]
└── .babelrc
1. [Link]
{
"name": "react-conditional-rendering",
"version": "1.0.0",
"scripts": {
"start": "webpack-dev-server"
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"webpack": "^5.74.0",
"webpack-cli": "^5.0.0",
"webpack-dev-server": "^4.11.1",
"babel-loader": "^9.1.2",
"@babel/core": "^7.22.11",
"@babel/preset-env": "^7.22.10",
"@babel/preset-react": "^7.22.5",
"html-webpack-plugin": "^5.5.3",
"css-loader": "^6.7.3",
"style-loader": "^3.3.2"
}
}
2. .babelrc
{
"presets": ["@babel/preset-env", "@babel/preset-react"]
}
function App() {
const [isVisible, setIsVisible] = useState(false);
return (
<div style={[Link]}>
<h1>React Conditional Rendering</h1>
// Render to DOM
const root = [Link]([Link]('root'));
[Link](<App />);
4. [Link] – Webpack Setup with Babel
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
[Link] = {
mode: 'development', // From knowledge base — enables development optimizations
entry: './src/[Link]',
output: {
filename: '[Link]',
path: [Link](__dirname, 'dist'),
clean: true,
},
devServer: {
static: './dist',
hot: true,
open: true
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader']
}
]
},
plugins: [
new HtmlWebpackPlugin({
templateContent: `
<!DOCTYPE html>
<html lang="en">
<head><title>React Conditional Rendering</title></head>
<body><div id="root"></div></body>
</html>
`,
inject: true
})
],
resolve: {
extensions: ['.js', '.jsx']
}
};
5. How to Run
1. Initialize project
npm init -y
2. Install dependencies
npm start
[Link]
Output:
[Link] – Conditional Rendering, Rendering Lists, React Forms
b. Write a program for rendering lists.
Program:
Functional components
Inline styling
Folder Structure
react-list-rendering/
│
├── src/
│ └── [Link]
│
├── [Link]
├── [Link]
└── .babelrc
1. [Link]
{
"name": "react-list-rendering",
"version": "1.0.0",
"scripts": {
"start": "webpack-dev-server"
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"webpack": "^5.74.0",
"webpack-cli": "^5.0.0",
"webpack-dev-server": "^4.11.1",
"babel-loader": "^9.1.2",
"@babel/core": "^7.22.11",
"@babel/preset-env": "^7.22.10",
"@babel/preset-react": "^7.22.5",
"html-webpack-plugin": "^5.5.3"
}
}
2. .babelrc
{
"presets": ["@babel/preset-env", "@babel/preset-react"]
}
3. src/[Link] – List Rendering Example
import React, { useState } from 'react';
import ReactDOM from 'react-dom/client';
function App() {
const [items, setItems] = useState([
{ id: 1, name: 'Apple' },
{ id: 2, name: 'Banana' },
{ id: 3, name: 'Cherry' }
]);
setItems([...items, newItemObj]);
setNewItem('');
}
};
return (
<div style={[Link]}>
<h1>React List Rendering</h1>
// Inline Styles
const styles = {
container: {
fontFamily: 'Arial',
textAlign: 'center',
padding: '40px'
},
list: {
listStyleType: 'none',
padding: 0,
margin: 'auto',
maxWidth: '300px',
textAlign: 'left'
},
listItem: {
padding: '10px',
borderBottom: '1px solid #ddd'
},
form: {
marginTop: '30px'
},
input: {
padding: '10px',
width: '200px',
fontSize: '16px'
},
button: {
marginLeft: '10px',
padding: '10px 15px',
fontSize: '16px',
backgroundColor: '#007bff',
color: 'white',
border: 'none',
borderRadius: '5px',
cursor: 'pointer'
}
};
// Render to DOM
const root = [Link]([Link]('root'));
[Link](<App />);
4. [Link] – Webpack Setup
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
[Link] = {
mode: 'development', // From knowledge base — better debugging
entry: './src/[Link]',
output: {
filename: '[Link]',
path: [Link](__dirname, 'dist'),
clean: true
},
devServer: {
static: './dist',
hot: true,
open: true
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
}
]
},
plugins: [
new HtmlWebpackPlugin({
templateContent: `
<!DOCTYPE html>
<html lang="en">
<head><title>React List Rendering</title></head>
<body><div id="root"></div></body>
</html>
`,
inject: true
})
],
resolve: {
extensions: ['.js', '.jsx']
}
};
How to Run
1. Initialize project
npm init -y
2. Install dependencies
[Link]
Output:
[Link] – Conditional Rendering, Rendering Lists, React Forms
c. Write a program for working with different form fields using react
forms.
Program:
working ReactJS program that demonstrates how to work with different form fields using
controlled components:
Features:
Text Input
Dropdown Select
Radio Buttons
Checkbox
Multiple Form Fields
Form Submission
useState for managing state
Folder Structure
react-form-fields/
│
├── src/
│ └── [Link]
│
├── [Link]
├── [Link]
└── .babelrc
1. [Link]
{
"name": "react-form-fields",
"version": "1.0.0",
"scripts": {
"start": "webpack-dev-server"
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"webpack": "^5.74.0",
"webpack-cli": "^5.0.0",
"webpack-dev-server": "^4.11.1",
"babel-loader": "^9.1.2",
"@babel/core": "^7.22.11",
"@babel/preset-env": "^7.22.10",
"@babel/preset-react": "^7.22.5",
"html-webpack-plugin": "^5.5.3"
}
}
2. .babelrc
{
"presets": ["@babel/preset-env", "@babel/preset-react"]
}
function App() {
const [formData, setFormData] = useState({
name: '',
color: 'red',
fruit: 'apple',
newsletter: false
});
setFormData({
...formData,
[name]: type === 'checkbox' ? checked : value
});
};
return (
<div style={[Link]}>
<h1>React Form Example</h1>
// Inline Styles
const styles = {
container: {
fontFamily: 'Arial',
padding: '40px'
},
form: {
display: 'flex',
flexDirection: 'column',
maxWidth: '400px',
margin: 'auto',
backgroundColor: '#f9f9f9',
padding: '20px',
borderRadius: '10px'
},
label: {
marginBottom: '15px',
display: 'block'
},
input: {
width: '100%',
padding: '8px',
marginTop: '5px',
fontSize: '16px'
},
select: {
width: '100%',
padding: '8px',
marginTop: '5px',
fontSize: '16px'
},
radioGroup: {
marginBottom: '15px'
},
radioLabel: {
display: 'block',
margin: '5px 0'
},
checkboxLabel: {
display: 'block',
marginBottom: '15px'
},
button: {
padding: '10px 20px',
fontSize: '16px',
backgroundColor: '#007bff',
color: 'white',
border: 'none',
cursor: 'pointer',
borderRadius: '5px'
},
output: {
marginTop: '30px',
textAlign: 'center'
}
};
// Render to DOM
const root = [Link]([Link]('root'));
[Link](<App />);
[Link] = {
mode: 'development', // From knowledge base — enables development optimizations
entry: './src/[Link]',
output: {
filename: '[Link]',
path: [Link](__dirname, 'dist'),
clean: true
},
devServer: {
static: './dist',
hot: true,
open: true
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
}
]
},
plugins: [
new HtmlWebpackPlugin({
templateContent: `
<!DOCTYPE html>
<html lang="en">
<head><title>React Form Fields</title></head>
<body><div id="root"></div></body>
</html>
`,
inject: true
})
],
resolve: {
extensions: ['.js', '.jsx']
}
};
How to Run
1. Initialize project
npm init -y
2. Install dependencies
npm start
[Link]
Output:
8. ReactJS – React Router, Updating the Screen
Program:
Multiple routes
Navigation links
Features
Feature Description
Folder Structure
react-router-demo/
│
├── src/
│ └── [Link]
│ └── [Link]
│
├── [Link]
├── [Link]
└── .babelrc
1. [Link]
{
"name": "react-router-demo",
"version": "1.0.0",
"scripts": {
"start": "webpack-dev-server"
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.22.0"
},
"devDependencies": {
"webpack": "^5.74.0",
"webpack-cli": "^5.0.0",
"webpack-dev-server": "^4.11.1",
"babel-loader": "^9.1.2",
"@babel/core": "^7.22.11",
"@babel/preset-env": "^7.22.10",
"@babel/preset-react": "^7.22.5",
"html-webpack-plugin": "^5.5.3"
}
}
2. .babelrc
{
"presets": ["@babel/preset-env", "@babel/preset-react"]
}
3. src/[Link]
container: {
fontFamily: 'Arial, sans-serif',
padding: '20px'
},
nav: {
marginBottom: '20px'
},
navList: {
listStyleType: 'none',
display: 'flex',
gap: '15px',
padding: 0
},
link: {
textDecoration: 'none',
color: '#007BFF',
fontWeight: 'bold'
},
main: {
padding: '20px',
backgroundColor: '#f9f9f9',
borderRadius: '8px'
}
};
[Link] = {
mode: 'development', // From knowledge base — better debugging
entry: './src/[Link]',
output: {
filename: '[Link]',
path: [Link](__dirname, 'dist'),
clean: true
},
devServer: {
static: './dist',
hot: true,
open: true
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
}
]
},
plugins: [
new HtmlWebpackPlugin({
templateContent: `
<!DOCTYPE html>
<html lang="en">
<head><title>React Router Demo</title></head>
<body><div id="root"></div></body>
</html>
`,
inject: true
})
],
resolve: {
extensions: ['.js', '.jsx']
}
};
How to Run:
1. Install dependencies
npm start
[Link]
You’ll see a navigation bar and content change dynamically when clicking links
like:
Home
About
Contact
View User 123
Output:
[Link] – React Router, Updating the Screen
b. Write a program for updating the screen.
Program:
ReactJS program that demonstrates how to update the screen dynamically, using:
Conditional rendering
Inline styling
This example shows how your UI can react to user interactions — such as typing in an input or clicking a
button — to update the screen.
Features
Feature Description
1. [Link]
{
"name": "react-screen-update",
"version": "1.0.0",
"scripts": {
"start": "webpack-dev-server"
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"webpack": "^5.74.0",
"webpack-cli": "^5.0.0",
"babel-loader": "^9.1.2",
"@babel/core": "^7.22.11",
"@babel/preset-env": "^7.22.10",
"@babel/preset-react": "^7.22.5",
"html-webpack-plugin": "^5.5.3",
"webpack-dev-server": "^4.11.1"
2. .babelrc
{
"presets": ["@babel/preset-env", "@babel/preset-react"]
}
function App() {
const [text, setText] = useState('');
const [displayText, setDisplayText] = useState('');
const [items, setItems] = useState(['Apple', 'Banana', 'Cherry']);
const [newItem, setNewItem] = useState('');
return (
<div style={[Link]}>
<h1>React: Updating the Screen</h1>
<div style={[Link]}>
<input
type="text"
placeholder="Add new item"
value={newItem}
onChange={(e) => setNewItem([Link])}
style={[Link]}
/>
<button onClick={addToList} style={[Link]}>Add Item</button>
</div>
</div>
</div>
);
}
// Inline Styles
const styles = {
container: {
fontFamily: 'Arial',
padding: '40px',
textAlign: 'center'
},
section: {
marginBottom: '40px'
},
input: {
width: '250px',
padding: '10px',
fontSize: '16px',
margin: '10px',
border: '1px solid #ccc',
borderRadius: '4px'
},
button: {
padding: '10px 15px',
fontSize: '16px',
backgroundColor: '#007bff',
color: 'white',
border: 'none',
borderRadius: '4px',
cursor: 'pointer'
},
output: {
marginTop: '20px',
padding: '20px',
backgroundColor: '#f0f8ff',
border: '1px solid #cce0ff',
borderRadius: '5px',
display: 'inline-block',
maxWidth: '500px'
},
list: {
listStyleType: 'none',
padding: 0,
textAlign: 'left',
display: 'inline-block',
width: '100%'
},
listItem: {
padding: '10px',
borderBottom: '1px solid #eee'
},
formGroup: {
marginTop: '20px'
},
hr: {
margin: '40px 0'
}
};
// Render to DOM
const root = [Link]([Link]('root'));
[Link](<App />);
[Link] = {
mode: 'development', // From knowledge base — better debugging
entry: './src/[Link]',
output: {
filename: '[Link]',
path: [Link](__dirname, 'dist'),
clean: true
},
devServer: {
static: './dist',
hot: true,
open: true
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
}
]
},
plugins: [
new HtmlWebpackPlugin({
templateContent: `
<!DOCTYPE html>
<html lang="en">
<head><title>React Screen Update</title></head>
<body><div id="root"></div></body>
</html>
`,
inject: true
})
],
resolve: {
extensions: ['.js', '.jsx']
}
};
How to Run:
1. Install dependencies
[Link]
Output:
9. ReactJS – Hooks, Sharing data between Components
[Link] a program to understand the importance of using hooks
Program:
ReactJS program that demonstrates the importance of using hooks, especially useState, to
manage state in functional components.
Features
Feature Description
Folder Structure
react-hooks-demo/
│
├── src/
│ └── [Link]
│
├── [Link]
├── [Link]
└── .babelrc
1. [Link]
{
"name": "react-hooks-demo",
"version": "1.0.0",
"scripts": {
"start": "webpack-dev-server"
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"webpack": "^5.74.0",
"webpack-cli": "^5.0.0",
"webpack-dev-server": "^4.11.1",
"babel-loader": "^9.1.2",
"@babel/core": "^7.22.11",
"@babel/preset-env": "^7.22.10",
"@babel/preset-react": "^7.22.5",
"html-webpack-plugin": "^5.5.3"
}
}
2. .babelrc
{
"presets": ["@babel/preset-env", "@babel/preset-react"]
}
3. src/[Link] – React Code Using useState Hook
import React, { useState } from 'react';
import ReactDOM from 'react-dom/client';
function App() {
const [text, setText] = useState('');
const [showText, setShowText] = useState(false);
return (
<div style={[Link]}>
<h1>React Hooks: Understanding `useState`</h1>
// Render to DOM
const root = [Link]([Link]('root'));
[Link](<App />);
[Link] = {
mode: 'development', // From knowledge base — better debugging
entry: './src/[Link]',
output: {
filename: '[Link]',
path: [Link](__dirname, 'dist'),
clean: true
},
devServer: {
static: './dist',
hot: true,
open: true
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
}
]
},
plugins: [
new HtmlWebpackPlugin({
templateContent: `
<!DOCTYPE html>
<html lang="en">
<head><title>React Hooks Demo</title></head>
<body><div id="root"></div></body>
</html>
`,
inject: true
})
],
resolve: {
extensions: ['.js', '.jsx']
}
};
How to Run:
1. Install dependencies
npm start
Webpack Dev Server will open your app at:
[Link]
Output:
[Link] – Hooks, Sharing data between Components
b. Write a program for sharing data between components.
Program:
Folder Structure
react-share-data/
│
├── src/
│ └── [Link]
│
├── [Link]
├── [Link]
└── .babelrc
1. [Link]
{
"name": "react-share-data",
"version": "1.0.0",
"scripts": {
"start": "webpack-dev-server"
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"webpack": "^5.74.0",
"webpack-cli": "^5.0.0",
"webpack-dev-server": "^4.11.1",
"babel-loader": "^9.1.2",
"@babel/core": "^7.22.11",
"@babel/preset-env": "^7.22.10",
"@babel/preset-react": "^7.22.5",
"html-webpack-plugin": "^5.5.3"
}
}
2. .babelrc
{
"presets": ["@babel/preset-env", "@babel/preset-react"]
}
return (
<div style={[Link]}>
<h2>Child Component</h2>
<p><strong>Message from Parent:</strong> {message || 'No message'}</p>
<button onClick={handleSend} style={[Link]}>Send Message to Parent</button>
</div>
);
}
return (
<div style={[Link]}>
<h1>React: Sharing Data Between Components</h1>
// Root Component
export default function App() {
return <ParentComponent />;
}
// Styles as JavaScript object
const styles = {
container: {
fontFamily: 'Arial',
padding: '40px'
},
card: {
border: '1px solid #ccc',
borderRadius: '10px',
padding: '20px',
maxWidth: '400px',
margin: 'auto',
boxShadow: '0 0 10px rgba(0,0,0,0.1)',
textAlign: 'center'
},
outputBox: {
marginTop: '30px',
padding: '20px',
backgroundColor: '#f0f8ff',
border: '1px solid #bee5eb',
borderRadius: '10px',
textAlign: 'center'
},
button: {
padding: '10px 15px',
fontSize: '16px',
backgroundColor: '#007bff',
color: 'white',
border: 'none',
borderRadius: '5px',
cursor: 'pointer'
}
};
// Render to DOM
const root = [Link]([Link]('root'));
[Link](<App />);
[Link] = {
mode: 'development', // From knowledge base — better debugging experience
entry: './src/[Link]',
output: {
filename: '[Link]',
path: [Link](__dirname, 'dist'),
clean: true
},
devServer: {
static: './dist',
hot: true,
open: true
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
}
]
},
plugins: [
new HtmlWebpackPlugin({
templateContent: `
<!DOCTYPE html>
<html lang="en">
<head><title>React Share Data</title></head>
<body><div id="root"></div></body>
</html>
`,
inject: true
})
],
resolve: {
extensions: ['.js', '.jsx']
}
};
How to Run:
1. Install dependencies
npm start
[Link]
Output:
10. MongoDB – Installation, Configuration, CRUD operations
Installation Guide:
For Windows:
Refer this Link
[Link]
Quires:
Insert multiple:
[Link]([
{ name: "Anita", age: 22, branch: "ECE" },
{ name: "Kiran", age: 20, branch: "MECH" }
])
Find all:
[Link]()
Pretty print:
[Link]().pretty()
C. Update Documents
Update one:
[Link](
{ name: "Ravi" },
{ $set: { age: 22 } }
)
Update many:
[Link](
{ branch: "CSE" },
{ $set: { semester: 6 } }
)
Delete one:
Delete many:
MongoDB queries to create and drop databases and collections, using the MongoDB Shell
(mongosh).
use <database_name>
Example:
use school
2. Drop a Collection
To drop a collection (remove it completely):
db.<collection_name>.drop()
Example:
[Link]()
Output:
3. Drop a Database
To drop an entire database:
Example:
use school
[Link]()
This deletes the entire school database, including all its collections and documents.
How to Run These Queries
1. Open MongoDB Shell:
mongosh
Quires:
find()
limit()
sort()
createIndex()
aggregate()
use company
[Link]([
{ name: "Alice", department: "HR", salary: 50000, age: 30 },
{ name: "Bob", department: "IT", salary: 70000, age: 28 },
{ name: "Charlie", department: "IT", salary: 60000, age: 35 },
{ name: "Diana", department: "HR", salary: 48000, age: 25 },
{ name: "Eve", department: "Finance", salary: 80000, age: 40 }
])
[Link]().pretty()
Find by condition:
[Link]({ salary: 1 })
[Link]()
[Link]([
{
$group: {
_id: "$department",
avgSalary: { $avg: "$salary" },
totalEmployees: { $sum: 1 }
}
}
])
Summary Table:
Operation Query
aggregate() [Link]([...])
[Link] Programs: (Any 2 must be completed)
a. Design a to-do list application using NodeJS and ExpressJS.
Program:
[Link]
[Link]
Add tasks
View all tasks
Mark task as completed
Delete tasks
File Structure:
Todo-app/
├── models/
│ └── [Link]
├── routes/
│ └── [Link]
├── views/
│ └── [Link]
├── public/
│ └── [Link]
├── [Link]
├── [Link]
├── .env
└── [Link]
npm init -y
PORT=3000
MONGO_URI=mongodb://localhost:27017/todoapp
Make sure MongoDB is running locally or update the URI for Atlas.
// Delete Todo
[Link]('/delete/:id', async (req, res) => {
await [Link]([Link]);
[Link]('/');
});
[Link] = router;
5. views/[Link] – Dynamic HTML Template
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>To-Do List</title>
<link rel="stylesheet" href="/[Link]" />
</head>
<body>
<div class="container">
<h1>🚀 To-Do List</h1>
body {
font-family: Arial, sans-serif;
background: #f4f4f4;
padding: 40px;
}
.container {
max-width: 500px;
margin: auto;
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
text-align: center;
}
h1 {
color: #333;
}
form {
display: flex;
justify-content: center;
gap: 10px;
margin-bottom: 20px;
}
input[type="text"] {
flex: 1;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
}
button {
padding: 10px 15px;
background-color: #007BFF;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
ul {
list-style: none;
padding: 0;
text-align: left;
}
li {
padding: 10px;
border-bottom: 1px solid #eee;
display: flex;
justify-content: space-between;
align-items: center;
}
.completed {
text-decoration: line-through;
color: gray;
}
.delete {
color: red;
text-decoration: none;
}
require('dotenv').config();
const express = require('express');
const mongoose = require('mongoose');
const path = require('path');
const app = express();
const PORT = [Link] || 3000;
// Middleware
[Link]('view engine', 'ejs');
[Link]('views', [Link](__dirname, 'views'));
[Link]([Link]({ extended: true }));
[Link]([Link]('public'));
// Routes
const todoRoutes = require('./routes/todoRoutes');
[Link](todoRoutes);
// MongoDB Connection
[Link]([Link].MONGO_URI)
.then(() => {
[Link]('✅Connected to MongoDB');
// Start server
[Link](PORT, () => {
[Link](`🚀 Server running at [Link]
});
})
.catch(err => {
[Link]('❌MongoDB connection error:', err);
});
8. [Link]:
const path = require('path');
return webpackModeConfig; };
9. [Link]:
{
"name": "todo-app",
"version": "1.0.0",
"description": "A simple To-Do List app using Express and MongoDB",
"main": "[Link]",
"scripts": {
},
"dependencies": {
"cors": "^2.8.5",
"dotenv": "^16.3.1",
"ejs": "^3.1.9",
"express": "^4.18.2",
"helmet": "^6.1.0",
"mongoose": "^7.0.3",
"morgan": "^1.10.0"
},
"devDependencies": {},
"engines": {
"node": ">=14"
},
"license": "MIT"
}
How to Run:
node [Link]
Open in browser:
[Link]
Output:
[Link] Programs: (Any 2 must be completed)
b. Design a Quiz app using ReactJS.
Program:
Multiple-choice quiz
State management with useState
Conditional rendering
Score tracking
You can expand this later to include a backend using Express + MongoDB.
Folder Structure
react-quiz-app/
├── public/
│ └── [Link]
├── src/
│ ├── [Link]
│ └── [Link]
├── styles/
│ └── [Link]
├── [Link]
├── [Link]
└── .babelrc
1. [Link]
{
"name": "react-quiz-app",
"version": "1.0.0",
"scripts": {
"start": "webpack-dev-server"
},
"dependencies": {
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
"devDependencies": {
"@babel/core": "^7.28.0",
"@babel/preset-env": "^7.28.0",
"@babel/preset-react": "^7.27.1",
"babel-loader": "^9.2.1",
"css-loader": "^7.1.2",
"html-webpack-plugin": "^5.6.3",
"style-loader": "^4.0.0",
"webpack": "^5.100.1",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.2"
}
}
2. .babelrc
{
"presets": ["@babel/preset-env", "@babel/preset-react"]
}
3. src/[Link] – React Quiz App
import React, { useState } from 'react';
import '../styles/[Link]';
function App() {
const [currentQuestion, setCurrentQuestion] = useState(0);
const [score, setScore] = useState(0);
const [showScore, setShowScore] = useState(false);
const questions = [
{
questionText: "What does ReactJS primarily use for state management?",
options: [
{ answerText: "Redux", isCorrect: true },
{ answerText: "jQuery", isCorrect: false },
{ answerText: "Axios", isCorrect: false },
{ answerText: "Express", isCorrect: false }
]
},
{
questionText: "Which company developed ReactJS?",
options: [
{ answerText: "Google", isCorrect: false },
{ answerText: "Facebook", isCorrect: true },
{ answerText: "Netflix", isCorrect: false },
{ answerText: "Twitter", isCorrect: false }
]
},
{
questionText: "What is ReactJS?",
options: [
{ answerText: "A library for building UI", isCorrect: true },
{ answerText: "A framework for server-side rendering", isCorrect: false },
{ answerText: "A database", isCorrect: false },
{ answerText: "A styling tool", isCorrect: false }
]
},
{
questionText: "Which of the following is used to pass data to a component in React?",
options: [
{ answerText: "Events", isCorrect: false },
{ answerText: "Hooks", isCorrect: false },
{ answerText: "Props", isCorrect: true },
{ answerText: "State", isCorrect: false }
]
},
{
questionText: "Which hook is used to manage state in React?",
options: [
{ answerText: "useEffect", isCorrect: false },
{ answerText: "useState", isCorrect: true },
{ answerText: "useRef", isCorrect: false },
{ answerText: "useContext", isCorrect: false }
]
}
];
return (
<div className="container">
<h1>React Quiz App</h1>
{showScore ? (
<div className="score-section">
<h2>You scored {score} out of {[Link]}</h2>
<button onClick={restartQuiz} className="restart-button">
Restart Quiz
</button>
</div>
):(
<>
<div className="question-section">
<div className="question-count">
<span>Question {currentQuestion + 1}/{[Link]}</span>
</div>
<div className="question-text">
{questions[currentQuestion].questionText}
</div>
</div>
<div className="answer-section">
{questions[currentQuestion].[Link]((option, index) => (
<button
key={index}
onClick={() => handleAnswerClick([Link])}
className="answer-button"
>
{[Link]}
</button>
))}
</div>
</>
)}
</div>
);
}
[Link]/[Link]:
/* Base Styles */
*{
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.container {
text-align: center;
padding: 40px;
max-width: 600px;
background: white;
border-radius: 10px;
box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}
h1 {
font-size: 2.5rem;
margin-bottom: 20px;
color: #333;
}
/* Question Section */
.question-section {
margin-bottom: 30px;
}
.question-count {
font-size: 18px;
margin-bottom: 10px;
color: #555;
}
.question-text {
font-size: 24px;
font-weight: bold;
margin-bottom: 20px;
color: #222;
}
/* Answer Buttons */
.answer-section {
display: flex;
flex-direction: column;
gap: 10px;
max-width: 400px;
margin: auto;
}
.answer-button {
padding: 15px;
font-size: 16px;
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease;
}
.answer-button:hover {
background-color: #0056b3;
}
/* Score Section */
.score-section {
font-size: 20px;
}
.score-section h2 {
margin-bottom: 20px;
color: #333;
}
.restart-button {
padding: 10px 20px;
font-size: 16px;
background-color: #28a745;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease;
}
.restart-button:hover {
background-color: #218838;
}
[Link]:
// [Link]
1. Install dependencies
npm start
[Link]
Output:
12. Augmented Programs: (Any 2 must be completed)
Instructions:
MongoDB University offers free online courses and certifications that you can
complete at your own pace. Here’s how to do it:
Step-by-Step Guide to Complete MongoDB Certification
[Link]