Project Documentation

FullStackJS Express + React

REST API with Express, Prisma & MySQL and a React single-page app with JWT login and user management

Version 1.0 · November 2026 · Learning project

Executive summary

FullStackJS Express + React is a beginner-friendly full-stack JavaScript project: a REST API built with Express, Prisma and MySQL, and a React single-page app that registers users, logs in with a JWT and manages users through a protected admin area.

The repository also contains FundamentalES6, a set of small exercises on modern JavaScript that the project builds on.

7REST endpoints
7React pages
JWTauthentication (1 hour)
23ES6 exercises

Open the live demo →

Features

Register & login

Sign up with name, e-mail and password; log in to receive a JWT that is stored in a cookie.

Protected routes

Admin pages redirect to login without a token; the API rejects requests without a valid token.

User management (CRUD)

List, add, edit and delete users from the admin area.

Server-side validation

express-validator checks required fields, e-mail format, unique e-mail and password length.

Password hashing

Passwords are hashed with bcrypt before they are stored.

Live demo

The real React app runs on GitHub Pages with the backend simulated in the browser.

Architecture

Frontend · React + Vite Backend · Express (port 3000) Data Pages (react-router)Home · Register · Login · Dashboard · Users AuthContext + js-cookietoken & user stored in cookies services/api.js (axios)baseURL http://localhost:3000 mockApi.js · demo onlysame rules, runs in the browser routes/index.js/api/register · /api/login middlewares/auth.jsverify JWT utils/validators · express-validatorname, e-mail format & uniqueness, password ≥ 6 controllers · Register · Login · Userbcryptjs · jsonwebtoken (1h) Prisma Clientprisma/schema.prisma · migrations MySQLdb_express · users localStoragedemo data
Locally the React app calls the Express API on port 3000. In the live demo the same requests are answered by mockApi.js inside the browser.
LayerTechnologyFolder
FrontendReact 18, Vite 5, react-router-dom 6, axios, js-cookie, Bootstrap 5frontend-react/
BackendExpress 4, express-validator, bcryptjs, jsonwebtoken, cors, body-parserbackend-express/
DatabaseMySQL + Prisma ORMbackend-express/prisma/
ExercisesJavaScript ES6+ (Node.js)FundamentalES6/

API reference

Base URL http://localhost:3000. Protected endpoints expect the JWT in the Authorization header (the raw token, without “Bearer”).

MethodEndpointAuthBodySuccess
POST/api/register—name, email, password201 Register successfully
POST/api/login—email, password200 { user, token }
GET/api/admin/usersJWT—200 users (newest first)
POST/api/admin/usersJWTname, email, password201 User created successfully
GET/api/admin/users/:idJWT—200 { id, name, email }
PUT/api/admin/users/:idJWTname, email, password200 User updated successfully
DELETE/api/admin/users/:idJWT—200 User deleted successfully

Error responses

HTTPWhenBody
422Validation failed{ success: false, message: "Validation error", errors: [{ path, msg, ... }] }
401No token / invalid or expired token / wrong passwordUnauthenticated. · Invalid token · Invalid password
404Login with an unknown e-mailUser not found
500Database error (e.g. updating or deleting an id that does not exist)Internal server error

Example

curl -X POST http://localhost:3000/api/login \
  -H "Content-Type: application/json" \
  -d '{"email": "admin@demo.com", "password": "password"}'

# use the token from the response
curl http://localhost:3000/api/admin/users -H "Authorization: <token>"

Data model & validation

FieldTypeRule
idInt, auto incrementPrimary key
nameVarChar(255)Required
emailVarChar(255), uniqueRequired, valid format, not used by another user
passwordVarChar(255)At least 6 characters, stored as a bcrypt hash
createdAt · updatedAtDateTimeSet automatically

Frontend pages

RoutePageAccess
/HomePublic
/registerRegisterGuests (logged-in users go to the dashboard)
/loginLoginGuests
/admin/dashboardDashboardLogged in
/admin/usersUser listLogged in
/admin/users/createAdd userLogged in
/admin/users/edit/:idEdit userLogged in

AuthContext keeps isAuthenticated in sync with the token cookie; the sidebar’s Logout removes the cookies and returns to the login page.

Live demo

GitHub Pages can only serve static files, so the Express server and MySQL cannot run there. The demo build therefore swaps axios’s network adapter for services/mockApi.js.

Run locally

  1. Create a MySQL database named db_express.
  2. Copy backend-express/.env.example to .env and set DATABASE_URL and JWT_SECRET.
  3. Start the API (port 3000):
cd backend-express
npm install
npx prisma migrate dev
node index.js
  1. Start the React app (Vite dev server):
cd frontend-react
npm install
npm run dev

To try the demo mode locally: VITE_DEMO=true npm run dev.

FundamentalES6

Short Node.js scripts that practise the JavaScript features used throughout the project:

let · const · var

variable, variable2, variable3

Arrow functions

ArrowFunction1 – 5

Template literals

TemplateStringLiteral

Destructuring

Destructuring, Destructuring2, Restructuring

Spread · Rest

SpreadOperator 1–2, RestParameter 1–2

Default parameters

DefaultParam, DefaultParam2

Array.map

ArrayMap

Promise · async/await

Promise, Promise2, AsyncAwait

Hello World

HelloWorld

Known limitations & improvements

Already improved

Ideas for next steps

Hide password hashes

Register, create and update return the full user including the password hash — select only id, name and e-mail.

Safer token storage

Use an HttpOnly cookie set by the server and the standard Bearer scheme.

Handle token expiry

Log the user out automatically when the API answers 401.

Optional password on edit

Allow updating name or e-mail without re-entering a password.

404 for unknown ids

Return 404 instead of 500 when a user id does not exist.

Deploy the backend

Host the API and a managed MySQL database so the demo can use the real backend.