Ex. No: 1 Creating Custom Module to Display DATE: Aim: To create a custom module in Node.js that returns the current date and time, and to import and use it in the main application. Algorithm 1. Start the program. 2. Create a new file for the custom module. 3. Define a function to get the current date and time using JavaScript Date object. 4. Export the function using module.exports 5. Create a main file. 6. Import the custom module using require() 7. Call the function from the module. 8. Display the current date and time in the console. 9. Stop the program. Program Step 1: Create a Module File (dateTimeModule.js) function getCurrentDateTime() { const currentDate = new Date(); return currentDate.toString(); } module.exports = getCurrentDateTime; Step 2: Create Main File (app.js) const getDateTime = require('./dateTimeModule'); const currentDateTime = getDateTime(); console.log("Current Date and Time:"); console.log(currentDateTime); Output Current Date and Time: Tue Mar 24 2026 10:45:30 GMT+0530 (India Standard Time) Result Thus, a custom module was successfully created in Node.js to return the current date and time, and it was imported and executed in the main application. Ex. No: 2 Create HTTP Server using createServer() DATE: Aim To create an HTTP server using Node.js that listens on a specified port and sends a response back to the client. Algorithm 1. Start the program 2. Import the built-in http module 3. Use createServer() method to create a server 4. Define request and response parameters 5. Write response using res.write() 6. End response using res.end() 7. Use listen() method to assign port number 8. Open browser and access the server 9. Stop the program Program server.js // Import http module const http = require('http'); // Create server const server = http.createServer((req, res) => { // Set response header res.writeHead(200, { 'Content-Type': 'text/plain' }); // Send response res.write("Hello! Server is running successfully."); // End response res.end(); }); // Listen on port 3000 server.listen(3000, () => { console.log("Server is running at http://localhost:3000/"); }); Output Server is running at http://localhost:3000/ Browser Output: Hello! Server is running successfully. Result Thus, an HTTP server was successfully created using Node.js createServer() method, which listens on a port and sends a response to the client. Ex. No: 03 Express.js Application – Hello World DATE: Aim To create a simple web application using Node.js and Express.js that displays “Hello World” on the homepage. Algorithm 1. Start the program 2. Install Express framework using npm install express 3. Import Express module 4. Create an Express application 5. Define a route for the homepage ( / ) 6. Send response “Hello World” using res.send() 7. Start the server using app.listen() 8. Open browser and navigate to localhost 9. Stop the program Program app.js // Import express module const express = require('express'); // Create express application const app = express(); // Define route for homepage app.get('/', (req, res) => { res.send("Hello World"); }); // Start server on port 3000 app.listen(3000, () => { console.log("Server is running at http://localhost:3000/"); }); Output Server is running at http://localhost:3000/ Browser Output: Hello World Result Thus, a simple web application was successfully created using Express.js , and the “Hello World” message was displayed on the homepage. Ex. No: 04 Node.js/Express Server Handling GET and POST Requests (JSON) DATE: Aim To build a simple server using Node.js and Express.js that handles GET and POST requests and returns data in JSON format. Algorithm 1. Start the program 2. Install Express using npm install express 3. Import Express module 4. Create an Express application 5. Use middleware express.json() to parse JSON data 6. Create a GET route to send JSON response 7. Create a POST route to receive and send JSON data 8. Start the server using app.listen() 9. Test using browser/Postman 10. Stop the program Program app.js // Import express module const express = require('express'); // Create app const app = express(); // Middleware to parse JSON data app.use(express.json()); // GET request app.get('/data', (req, res) => { res.json({ message: "This is a GET request", status: "Success" }); }); // POST request app.post('/data', (req, res) => { const receivedData = req.body; res.json({ message: "POST request received", data: receivedData }); }); // Start server app.listen(3000, () => { console.log("Server running at http://localhost:3000/"); }); Output Server Output Server running at http://localhost:3000/ GET Request Output (Browser/Postman) { "message": "This is a GET request", "status": "Success" } POST Request Output (Postman) { "message": "POST request received", "data": { "name": "John", "age": 25 } } Result Thus, a server was successfully built using Express.js to handle GET and POST requests and return data in JSON format. Ex. No: 05 CRUD Operations in MongoDB using Node.js/Express DATE: Aim To build an application using Node.js , Express.js , and MongoDB to perform basic CRUD (Create, Read, Update, Delete) operations. Algorithm 1. Start the program 2. Install required packages: express , mongoose 3. Import required modules 4. Connect to MongoDB database 5. Create a schema and model 6. Implement CREATE operation using POST 7. Implement READ operation using GET 8. Implement UPDATE operation using PUT 9. Implement DELETE operation using DELETE 10. Start the server 11. Test using Postman 12. Stop the program Program app.js const express = require('express'); const mongoose = require('mongoose'); const app = express(); app.use(express.json()); // Connect to MongoDB mongoose.connect('mongodb://127.0.0.1:27017/studentDB') .then(() => console.log("MongoDB Connected")) .catch(err => console.log(err)); // Schema const StudentSchema = new mongoose.Schema({ name: String, age: Number }); // Model const Student = mongoose.model('Student', StudentSchema); // CREATE app.post('/add', async (req, res) => { const student = new Student(req.body); await student.save(); res.json({ message: "Data Added", student }); }); // READ app.get('/students', async (req, res) => { const data = await Student.find(); res.json(data); }); // UPDATE app.put('/update/:id', async (req, res) => { const updated = await Student.findByIdAndUpdate(req.params.id, req.body, { new: true }); res.json(updated); }); // DELETE app.delete('/delete/:id', async (req, res) => { await Student.findByIdAndDelete(req.params.id); res.json({ message: "Data Deleted" }); }); // Server app.listen(3000, () => { console.log("Server running at http://localhost:3000/"); }); Output Server Output MongoDB Connected Server running at http://localhost:3000/ POST (Create) Output { "message": "Data Added", "student": { "name": "John", "age": 22 } } GET (Read) Output [ { "_id": "12345", "name": "John", "age": 22 } ] PUT (Update) Output { "_id": "12345", "name": "John Updated", "age": 23 } DELETE Output { "message": "Data Deleted" } Result Thus, CRUD operations were successfully implemented using MongoDB with Express.js and Node.js Ex. No: 06 Building MongoDB Database for To-Do List Application DATE: Aim To design and create a database for a To-Do List application using MongoDB with Node.js and Express.js Algorithm 1. Start the program 2. Install required packages: mongoose , express 3. Import required modules 4. Connect to MongoDB database 5. Create a schema for To-Do items 6. Define fields such as task and status 7. Create a model using the schema 8. Insert sample data into the database 9. Retrieve data from the database 10. Display the stored To-Do items 11. Stop the program Program app.js const express = require('express'); const mongoose = require('mongoose'); const app = express(); app.use(express.json()); // Connect to MongoDB mongoose.connect('mongodb://127.0.0.1:27017/todoDB') .then(() => console.log("MongoDB Connected")) .catch(err => console.log(err)); // Create Schema const TodoSchema = new mongoose.Schema({ task: String, status: { type: Boolean, default: false } }); // Create Model const Todo = mongoose.model('Todo', TodoSchema); // Insert Data app.post('/add', async (req, res) => { const todo = new Todo(req.body); await todo.save(); res.json({ message: "Task Added", todo }); }); // Fetch Data app.get('/todos', async (req, res) => { const data = await Todo.find(); res.json(data); }); // Start Server app.listen(3000, () => { console.log("Server running at http://localhost:3000/"); }); Output Server Output MongoDB Connected Server running at http://localhost:3000/ POST Output (Add Task) { "message": "Task Added", "todo": { "task": "Complete Lab Record", "status": false } } GET Output (View Tasks) [ { "_id": "12345", "task": "Complete Lab Record", "status": false } ] Result Thus, a MongoDB database for the To-Do List application was successfully created using MongoDB , and data was inserted and retrieved using Express.js and Node.js Ex. No: 07 Simple Calculator Application using React JS DATE: Aim To create a simple calculator application using React that performs basic arithmetic operations like addition, subtraction, multiplication, and division. Algorithm 1. Start the program 2. Create a React application using create-react-app 3. Design the calculator UI with input fields and buttons 4. Use useState hook to store input values and result 5. Create functions for addition, subtraction, multiplication, and division 6. Perform calculations based on user input 7. Display the result on the screen 8. Run the application in the browser 9. Stop the program Program App.js import React, { useState } from 'react'; function App() { const [num1, setNum1] = useState(''); const [num2, setNum2] = useState(''); const [result, setResult] = useState(''); const add = () => setResult(Number(num1) + Number(num2)); const sub = () => setResult(Number(num1) - Number(num2)); const mul = () => setResult(Number(num1) * Number(num2)); const div = () => setResult(Number(num1) / Number(num2)); return ( <div style={{ textAlign: 'center', marginTop: '50px' }}> <h2>Simple Calculator</h2> <input type="number" placeholder="Enter first number" value={num1} onChange={(e) => setNum1(e.target.value)} /><br /><br /> <input type="number" placeholder="Enter second number" value={num2} onChange={(e) => setNum2(e.target.value)} /><br /><br /> <button onClick={add}>Add</button> <button onClick={sub}>Subtract</button> <button onClick={mul}>Multiply</button> <button onClick={div}>Divide</button> <h3>Result: {result}</h3> </div> ); } export default App; Output Browser Output: Simple Calculator [Enter first number] [Enter second number] [Add] [Subtract] [Multiply] [Divide] Result: 15 (Example: 10 + 5 = 15) Result Thus, a simple calculator application was successfully developed using React , and basic arithmetic operations were performed correctly. Ex. No: 08 React Application – List of Items with Add Functionality DATE: Aim To build a simple application using React that displays a list of items and allows the user to add new items dynamically. Algorithm 1. Start the program 2. Create a React application using create-react-app 3. Import useState hook 4. Initialize state to store list items 5. Create an input field to accept user input 6. Create a button to add items to the list 7. Update state using setItems() 8. Display items using map() function 9. Run the application in the browser 10. Stop the program Program App.js import React, { useState } from 'react'; function App() { const [items, setItems] = useState([]); const [input, setInput] = useState(''); const addItem = () => { if (input.trim() !== '') { setItems([...items, input]); setInput(''); } }; return ( <div style={{ textAlign: 'center', marginTop: '50px' }}> <h2>Item List App</h2> <input type="text" placeholder="Enter item" value={input} onChange={(e) => setInput(e.target.value)} /><br /><br /> <button onClick={addItem}>Add Item</button> <ul> {items.map((item, index) => ( <li key={index}>{item}</li> ))} </ul> </div> ); } export default App; Output Browser Output: Item List App [Enter item] [Add Item] • Apple • Banana • Mango Result Thus, a React application was successfully developed using React to display and dynamically add items to a list. Ex. No: 09 Simple Login Form using React JS DATE: Aim To create a simple login form using React that accepts username and password input from the user. Algorithm 1. Start the program 2. Create a React application using create-react-app 3. Import useState hook 4. Create state variables for username and password 5. Design a login form with input fields 6. Handle input changes using event handlers 7. Create a submit function to validate/display data 8. Display login message on submission 9. Run the application in browser 10. Stop the program Program App.js import React, { useState } from 'react'; function App() { const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [message, setMessage] = useState(''); const handleLogin = (e) => { e.preventDefault(); if (username === "admin" && password === "1234") { setMessage("Login Successful"); } else { setMessage("Invalid Credentials"); } }; return ( <div style={{ textAlign: 'center', marginTop: '50px' }}> <h2>Login Form</h2> <form onSubmit={handleLogin}> <input type="text" placeholder="Enter Username" value={username} onChange={(e) => setUsername(e.target.value)} /><br /><br /> <input type="password" placeholder="Enter Password" value={password} onChange={(e) => setPassword(e.target.value)} /><br /><br /> <button type="submit">Login</button> </form> <h3>{message}</h3> </div> ); } export default App; Output Browser Output: Login Form [Enter Username] [Enter Password] [Login Button] Login Successful (If correct credentials are entered: admin / 1234) Result Thus, a simple login form was successfully created using React , and user input was validated correctly. Ex. No: 10 E-Commerce Application using MERN Stack DATE: Aim To build a simple E-Commerce application using React , Express.js , Node.js , and MongoDB to display products and manage a shopping cart. Algorithm 1. Start the program 2. Setup backend using Node.js and Express 3. Connect to MongoDB database 4. Create product schema and API 5. Setup frontend using React 6. Fetch product data using API 7. Display products in UI 8. Add items to cart 9. Display cart items 10. Run the application 11. Stop the program Program Backend (server.js) const express = require('express'); const app = express(); app.use(express.json()); // Sample products const products = [ { id: 1, name: "Laptop", price: 50000 }, { id: 2, name: "Mobile", price: 20000 } ]; // API to get products app.get('/products', (req, res) => { res.json(products); }); app.listen(3000, () => { console.log("Server running on port 3000"); });