Skip to content

abhikawle/mernbasics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Full Project (Backend + Frontend)

This project contains a backend (Node.js + Express + MongoDB) and a React frontend.

🚀 Quick Start

Prerequisites

Run Backend & Frontend

Terminal 1 — Backend:

cd backend
npm install
cp .env.example .env
# Edit .env with your MONGO_URI and JWT_SECRET
npm run dev

Expected output: MongoDB connected and Server running on port 5000

Terminal 2 — Frontend:

cd frontend
npm install
npm start

This opens http://localhost:3000 in your browser automatically.


📖 Full Setup Guide

1. Backend Setup

cd backend
npm install

Copy environment file:

cp .env.example .env

Edit .env and configure:

PORT=5000
MONGO_URI=mongodb://localhost:27017/intern_assignment
JWT_SECRET=your_secure_secret_key_here

For MongoDB Atlas: Replace MONGO_URI with your connection string:

MONGO_URI=mongodb+srv://<username>:<password>@cluster.mongodb.net/intern_assignment

Start dev server with auto-reload:

npm run dev

Or production mode:

npm start

2. Frontend Setup

cd frontend
npm install
npm start

The app opens at http://localhost:3000


🧪 Test the App

Test Credentials

Field Value
Email demo@test.com
Password Demo@123

Steps to Test:

  1. Open http://localhost:3000
  2. Click Login
  3. Enter credentials above
  4. Create, view, edit, or delete items

📚 API Endpoints

Authentication

  • POST /api/v1/auth/register — Register new user
  • POST /api/v1/auth/login — Login and get token

Items (Require Authentication)

  • GET /api/v1/items — Fetch all user items
  • POST /api/v1/items — Create new item
  • PUT /api/v1/items/:id — Update item
  • DELETE /api/v1/items/:id — Delete item

🛠 Troubleshooting

Port Already in Use

# Find process on port 5000
netstat -ano | findstr ":5000"
# Kill it (replace <PID>)
taskkill /PID <PID> /F

MongoDB Connection Failed

  • Ensure MongoDB is running locally: mongod
  • Or verify your Atlas connection string in .env

Frontend Won't Start

# Try different port
set PORT=3001
npm start

📁 Project Structure

project/
├── backend/              # Node.js/Express API
│   ├── server.js         # Entry point
│   ├── config/db.js      # MongoDB config
│   ├── controllers/      # Route logic
│   ├── models/           # Mongoose schemas
│   ├── routes/           # API routes
│   ├── middlewares/      # Auth & error handling
│   ├── package.json
│   └── .env              # Environment variables
│
├── frontend/             # React app
│   ├── src/
│   │   ├── App.js        # Main component
│   │   ├── pages/        # Pages (Login, Register, Dashboard)
│   │   ├── api/          # API calls
│   │   └── index.js      # React entry
│   ├── package.json
│   └── public/
│
├── README.md             # This file
└── RUNNING.md            # Detailed run guide

📦 Build for Production

Build Frontend:

cd frontend
npm run build
# Output: build/ folder (ready to deploy)

Run Backend in Production:

cd backend
npm start

Notes

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors