Skip to content

PLP-MERN-Stack-Development/Week-4-MERN-Notes-App

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Week 4 MERN Notes App

A full-stack MERN (MongoDB, Express, React, Node.js) application for managing notes with a modern UI built using React, Tailwind CSS, and Radix UI components.

πŸ“‹ Table of Contents

✨ Features

  • βœ… Create, Read, Update, and Delete (CRUD) notes
  • βœ… User-specific notes with userId filtering
  • βœ… Real-time note updates
  • βœ… Responsive design with Tailwind CSS
  • βœ… Modal dialogs for creating notes
  • βœ… Inline editing for existing notes
  • βœ… Timestamps for note creation and updates
  • βœ… Modern UI components using Radix UI

πŸ› οΈ Tech Stack

Frontend

  • React (v19.1.1) - UI library
  • Vite (v7.1.7) - Build tool and dev server
  • Tailwind CSS (v4.1.14) - Utility-first CSS framework
  • Radix UI - Accessible UI components
  • Axios (v1.12.2) - HTTP client
  • Class Variance Authority - Component variant management

Backend

  • Node.js - Runtime environment
  • Express (v5.1.0) - Web framework
  • MongoDB - NoSQL database
  • Mongoose (v8.19.1) - ODM for MongoDB
  • CORS - Cross-origin resource sharing
  • dotenv - Environment variable management

πŸ“ Project Structure

week4-notes/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ config/
β”‚   β”‚   β”‚   └── db.js              # Database connection
β”‚   β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”‚   └── Notes.js           # Note schema/model
β”‚   β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”‚   └── notes.js           # API routes
β”‚   β”‚   └── server.js              # Express server setup
β”‚   └── package.json
β”‚
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ assets/                # Static assets
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ ui/                # Reusable UI components
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ button.jsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ card.jsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ input.jsx
β”‚   β”‚   β”‚   β”‚   └── textarea.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ NewNoteDialog.jsx  # Create note modal
β”‚   β”‚   β”‚   └── NoteCard.jsx       # Note display card
β”‚   β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”‚   β”œβ”€β”€ api.js             # API client
β”‚   β”‚   β”‚   └── utils.js           # Utility functions
β”‚   β”‚   β”œβ”€β”€ pages/
β”‚   β”‚   β”‚   └── Dashboard.jsx      # Main dashboard
β”‚   β”‚   β”œβ”€β”€ App.jsx                # Root component
β”‚   β”‚   β”œβ”€β”€ main.jsx               # Entry point
β”‚   β”‚   └── index.css              # Global styles
β”‚   β”œβ”€β”€ vite.config.js             # Vite configuration
β”‚   └── package.json
β”‚
└── README.md

πŸ“‹ Prerequisites

Before you begin, ensure you have the following installed:

  • Node.js (v16 or higher)
  • npm or yarn
  • MongoDB (local installation or MongoDB Atlas account)

πŸš€ Installation

1. Clone the repository

git clone https://github.com/PLP-MERN-Stack-Development/Week-4-MERN-Notes-App.git
cd Week-4-MERN-Notes-App

2. Install Backend Dependencies

cd backend
npm install

3. Install Frontend Dependencies

cd ../frontend
npm install

βš™οΈ Configuration

Backend Configuration

  1. Create a .env file in the backend directory:
cd backend
touch .env
  1. Add the following environment variables:
# MongoDB Connection String
MONGODB_URI=mongodb://localhost:27017/notes-app
# or for MongoDB Atlas:
# MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/notes-app

# Server Port
PORT=5000

# Allowed Frontend Origin
ALLOWED_ORIGIN=http://localhost:5173

Frontend Configuration

  1. Create a .env file in the frontend directory:
cd frontend
touch .env
  1. Add the following environment variable:
VITE_API_URL=http://localhost:5000

πŸƒ Running the Application

Start the Backend Server

cd backend
npm run dev

The backend server will start on http://localhost:5000

Start the Frontend Development Server

In a new terminal:

cd frontend
npm run dev

The frontend will start on http://localhost:5173

Access the Application

Open your browser and navigate to:

http://localhost:5173

πŸ“‘ API Endpoints

Notes Endpoints

Method Endpoint Description Request Body
GET /api/notes Get all notes (optionally filtered by userId) Query: ?userId=demo-abc-123
POST /api/notes Create a new note { title, content, userId }
PUT /api/notes/:id Update a note by ID { title, content }
DELETE /api/notes/:id Delete a note by ID -

Example Requests

Get all notes for a user

GET http://localhost:5000/api/notes?userId=demo-abc-123

Create a new note

POST http://localhost:5000/api/notes
Content-Type: application/json

{
  "title": "My First Note",
  "content": "This is the content of my note",
  "userId": "demo-abc-123"
}

Update a note

PUT http://localhost:5000/api/notes/65f1234567890abcdef12345
Content-Type: application/json

{
  "title": "Updated Title",
  "content": "Updated content"
}

Delete a note

DELETE http://localhost:5000/api/notes/65f1234567890abcdef12345

πŸ› Known Issues & Fixes

Issue 1: Path Alias Resolution Error

Error: Failed to resolve import "@/lib/utils"

Fix: Ensure vite.config.js has the path alias configured:

import { defineConfig } from 'vite'
import tailwindcss from '@tailwindcss/vite'
import react from '@vitejs/plugin-react'
import path from 'path'

export default defineConfig({
  plugins: [react(), tailwindcss()],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src')
    }
  }
})

Issue 2: Named vs Default Exports

Error: The requested module does not provide an export named 'default'

Fix: Import UI components as named exports:

// βœ… Correct
import { Button } from "./ui/button";
import { Input } from "./ui/input";
import { Textarea } from "./ui/textarea";

// ❌ Wrong
import Button from "./ui/button";

Issue 3: Missing Slash in API URLs

Error: Update/Delete requests fail

Fix: Add missing slashes in frontend/src/lib/api.js:

// Line 24 - Update endpoint
const res = await client.put(`/api/notes/${id}`, payload);

// Line 29 - Delete endpoint
const res = await client.delete(`/api/notes/${id}`);

Issue 4: Wrong Request Parameter Type in Backend

Error: GET /api/notes returns no data or 500 error

Fix: Change req.body to req.query in backend/src/routes/notes.js:

// Line 8
const { userId } = req.query;  // βœ… Correct
// NOT: const { userId } = req.body;  // ❌ Wrong

Issue 5: Missing Error Handling

Error: Server crashes on database errors

Fix: Wrap all async route handlers in try-catch blocks:

router.get("/", async (req, res) => {
    try {
        const { userId } = req.query;
        const filter = userId ? { userId } : {};
        const notes = await Note.find(filter).sort({ createdAt: -1});
        res.json(notes);
    } catch (error) {
        res.status(500).json({ message: error.message });
    }
});

🀝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“ License

This project is part of the PLP MERN Stack Development course.

πŸ‘₯ Authors

  • PLP MERN Stack Development Team

πŸ™ Acknowledgments

  • PLP Academy for the MERN Stack curriculum
  • Radix UI for accessible component primitives
  • Tailwind CSS for the utility-first CSS framework

Happy Coding! πŸš€

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published