├── index.js ├── db.js ├── package.json ├── model.js ├── routes.js └── README.md /index.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const app = express(); 3 | const route = require("./routes"); 4 | require("./db"); 5 | 6 | app.use(express.json()); 7 | app.use("/todo",route); 8 | 9 | 10 | 11 | app.listen(3000,()=>{ 12 | console.log("server started"); 13 | }); -------------------------------------------------------------------------------- /db.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | const URI = "mongodb+srv://oggy:MmxqrkPbhAXpPzRq@database.9s4d3kt.mongodb.net/?retryWrites=true&w=majority&appName=database"; 3 | 4 | async function main(){ 5 | await mongoose.connect(URI,{ 6 | dbName:"sample_mflix" 7 | }); 8 | } 9 | 10 | main().then(()=>{ 11 | console.log("db connected"); 12 | }) -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "exp", 3 | "version": "1.0.0", 4 | "description": "", 5 | "license": "ISC", 6 | "author": "", 7 | "type": "commonjs", 8 | "main": "index.js", 9 | "scripts": { 10 | "test": "echo \"Error: no test specified\" && exit 1", 11 | "dev": "npx nodemon node index.js" 12 | }, 13 | "dependencies": { 14 | "express": "^5.1.0", 15 | "mongoose": "^8.13.2", 16 | "nodemon": "^3.1.9" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /model.js: -------------------------------------------------------------------------------- 1 | const mongoose = require('mongoose'); 2 | /* const studentSchema = new mongoose.Schema({ 3 | name:String, 4 | age:String, 5 | year:String 6 | },{ 7 | timestamps:true 8 | }); 9 | const student = mongoose.model('student',studentSchema); 10 | 11 | */ 12 | 13 | const MoviesSchema = new mongoose.Schema({ 14 | plot:String, 15 | title:String 16 | },{ 17 | timestamps:true 18 | }); 19 | const movies = mongoose.model('movies',MoviesSchema); 20 | 21 | async function getpage(data,limit){ 22 | const toshow =movies.find({},{title:1,plot:1}).skip(data).limit(limit); 23 | return toshow; 24 | } 25 | 26 | 27 | module.exports = getpage; 28 | -------------------------------------------------------------------------------- /routes.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const route = express.Router(); 3 | 4 | const getpage = require('./model.js'); 5 | 6 | route.get('/pageno/:page',async(req,res)=>{ 7 | const page = parseInt(req.params.page); 8 | const limit = 10; 9 | const data = (page-1)*limit; 10 | const disp = await getpage(data,limit); 11 | res.send(disp); 12 | }) 13 | 14 | /* const student = require("./model.js"); 15 | route.post('/',(req,res)=>{ 16 | const {name,age,year} = req.body; 17 | const data = student.create({name,age,year}); 18 | if(data){ 19 | res.send("inserted successfully"); 20 | } 21 | 22 | }); 23 | 24 | route.get('/',async(req,res)=>{ 25 | const data = await student.find(); 26 | res.send(data); 27 | 28 | }) 29 | 30 | route.delete('/:id',async(req,res)=>{ 31 | const {id} = req.params; 32 | await student.findByIdAndDelete(id); 33 | res.send({success:true}); 34 | }) 35 | 36 | route.put('/:id',async(req,res)=>{ 37 | const {id} = req.params; 38 | const{name,age,year} = req.body; 39 | const updated = await student.findByIdAndUpdate(id,{name,age,year},{new:true}); 40 | res.send(updated); 41 | 42 | }) 43 | 44 | 45 | */ 46 | 47 | module.exports = route; -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MERN_Training 2 | 3 | Welcome to the **MERN_Training** repository! 4 | This project is a hands-on training repository to learn and practice full-stack web development using the MERN stack — MongoDB, Express.js, React.js, and Node.js. 5 | 6 | --- 7 | 8 | ## 🚀 Technologies Used 9 | 10 | - **Frontend:** React.js 11 | - **Backend:** Node.js, Express.js 12 | - **Database:** MongoDB (with Mongoose ODM) 13 | - **Other:** 14 | - Axios (for API calls) 15 | - JWT (for authentication, if implemented) 16 | - Nodemon (for development) 17 | 18 | --- 19 | 20 | ## 📂 Project Structure 21 | 22 | ``` 23 | 24 | MERN\_Training/ 25 | ├── backend/ # Backend server code (Node, Express, MongoDB) 26 | │ ├── config/ # Database and environment config 27 | │ ├── controllers/ # Controller functions for API endpoints 28 | │ ├── models/ # Mongoose schemas and models 29 | │ ├── routes/ # API routes 30 | │ └── server.js # Backend entry point 31 | ├── frontend/ # React frontend application 32 | │ ├── public/ # Public assets 33 | │ ├── src/ # React components, services, styles 34 | │ └── package.json # Frontend dependencies 35 | ├── .env # Environment variables (for backend) 36 | ├── README.md # Project documentation 37 | └── package.json # Backend dependencies 38 | 39 | ```` 40 | 41 | --- 42 | 43 | ## 💡 Features 44 | 45 | - CRUD operations with MongoDB 46 | - RESTful API with Express.js 47 | - Frontend UI built with React 48 | - API integration using Axios 49 | - State management with React Hooks 50 | - Basic authentication (if applicable) 51 | - Error handling and validation 52 | 53 | --- 54 | 55 | ## 🛠️ Installation and Setup 56 | 57 | ### 1. Clone the repository 58 | 59 | ```bash 60 | git clone https://github.com/santhu643/MERN_Training.git 61 | ```` 62 | 63 | ### 2. Setup Backend 64 | 65 | ```bash 66 | cd MERN_Training/backend 67 | npm install 68 | ``` 69 | 70 | * Create a `.env` file in the `backend` folder and add: 71 | 72 | ``` 73 | MONGO_URI=your_mongodb_connection_string 74 | PORT=5000 75 | ``` 76 | 77 | * Start the backend server: 78 | 79 | ```bash 80 | npm start 81 | ``` 82 | 83 | ### 3. Setup Frontend 84 | 85 | Open a new terminal window/tab: 86 | 87 | ```bash 88 | cd MERN_Training/frontend 89 | npm install 90 | npm start 91 | ``` 92 | 93 | The React app will run at `http://localhost:3000` and the backend API will run at `http://localhost:5000`. 94 | 95 | --- 96 | 97 | ## 🎯 Goals and Learning Outcomes 98 | 99 | * Understand how to build a full-stack web application 100 | * Master integration between React frontend and Node/Express backend 101 | * Learn MongoDB CRUD operations with Mongoose 102 | * Gain experience in asynchronous API calls with Axios 103 | * Practice environment configuration and deployment readiness 104 | 105 | --- 106 | 107 | ## 📬 Connect with Me 108 | 🔗 LinkedIn - https://www.linkedin.com/in/santhiya-prakash-87449425a/ 109 | 110 | 💻 GitHub - https://github.com/santhu643 111 | 112 | 🧠 LeetCode - https://leetcode.com/u/santhiyaprakash/ 113 | 114 | --- 115 | 116 | ## 📄 License 117 | 118 | This project is open-sourced under the MIT License. 119 | Feel free to use, modify, and share! 120 | 121 | --- 122 | 123 | **Happy Coding! 🚀** 124 | --------------------------------------------------------------------------------