Stop 12 · DatabasesProjects · 1/1

Notes App with a Database

Part of the Web Development Roadmap

In short

This is the project where everything you've learned connects: a React frontend, an Express API and a real database. Notes you write on your laptop will still be there tomorrow on your phone.

A full-stack notes app with a React frontend and an Express API that saves notes in MongoDB or PostgreSQL, so notes survive restarts and work across devices.

The jaadu stands behind a library counter writing carefully in a big bound register, with a tall wooden cupboard of identical registers behind it.

Think of it like this

The library register

A sticky note on your desk gets lost when you clean up. The library's register is different: the librarian writes every entry in a book kept in a safe cupboard, and anyone at the counter can look it up later. localStorage is the sticky note. A database behind an API is the register with a librarian.

Watch it happen

Saving a new note

React app
Express API
MongoDB

POST /api/notes { title, body }

1/5The form submits with fetch, sending JSON.

The big ideas

What you need to know

Full CRUD

Create, read, update and delete notes, plus search by title. Each maps to a route: POST, GET, PATCH, DELETE.

Two folders

Keep client (Vite React app) and server (Express API) as separate folders in one repo, each with its own package.json.

Secrets in .env

The database connection string goes in server/.env and is read with process.env. Never commit it.

Handle every state

Show loading, error and empty states in the UI, and return proper status codes from the API.

How it works

Build order that avoids getting stuck

  1. 1

    Model

    Define the Note schema: title (required), body, timestamps.

  2. 2

    API

    Write the five routes and test each one in Postman before touching React.

  3. 3

    Read

    In React, fetch and list notes with loading and empty states.

  4. 4

    Write

    Add the create form, then edit and delete.

  5. 5

    Search

    Add ?q= search on the API and a search box in the UI.

See it in code

Walk through the code

js
1// server/index.js2import "dotenv/config";3import express from "express";4import cors from "cors";5import mongoose from "mongoose";6 7const noteSchema = new mongoose.Schema(8  { title: { type: String, required: true, trim: true }, body: String },9  { timestamps: true }10);11const Note = mongoose.model("Note", noteSchema);12 13const app = express();14app.use(cors({ origin: "http://localhost:5173" }));15app.use(express.json());16 17app.get("/api/notes", async (req, res) => {18  const q = String(req.query.q || "");19  const notes = await Note.find({ title: { $regex: q, $options: "i" } }).sort({ updatedAt: -1 });20  res.json(notes);21});22 23app.post("/api/notes", async (req, res) => {24  if (!req.body.title) return res.status(400).json({ error: "Title is required" });25  const note = await Note.create({ title: req.body.title, body: req.body.body });26  res.status(201).json(note);27});28 29app.patch("/api/notes/:id", async (req, res) => {30  const note = await Note.findByIdAndUpdate(req.params.id, req.body, { new: true, runValidators: true });31  if (!note) return res.status(404).json({ error: "Note not found" });32  res.json(note);33});34 35app.delete("/api/notes/:id", async (req, res) => {36  const note = await Note.findByIdAndDelete(req.params.id);37  if (!note) return res.status(404).json({ error: "Note not found" });38  res.status(204).end();39});40 41await mongoose.connect(process.env.MONGODB_URI);42app.listen(4000, () => console.log("API on http://localhost:4000"));

1/7Loads MONGODB_URI from the .env file into process.env.

The whole API in one file to start with. Install with npm i express cors mongoose dotenv and add "type": "module" to package.json. Express 5 passes async errors to its error handler; on Express 4, wrap routes in try/catch.

Save yourself the pain

Common mistakes

Oops

Committing the .env file with your database password to GitHub.

Do this instead

Add .env to .gitignore before the first commit, and commit a .env.example with empty values instead.

Oops

Building the React UI before the API works.

Do this instead

Test every route in Postman first. Then frontend bugs and backend bugs never get mixed up.

Your mission

Ship the notes app

~240 min

Quick check

Why does the notes app use a database instead of localStorage?

Go deeper

  1. 1Support create, edit, delete and search for notes.
  2. 2Keep the database connection string in an environment variable.
  3. 3Show loading and error states in the React app for every API call.

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge