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.
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
| Layer | Technology | Folder |
|---|---|---|
| Frontend | React 18, Vite 5, react-router-dom 6, axios, js-cookie, Bootstrap 5 | frontend-react/ |
| Backend | Express 4, express-validator, bcryptjs, jsonwebtoken, cors, body-parser | backend-express/ |
| Database | MySQL + Prisma ORM | backend-express/prisma/ |
| Exercises | JavaScript 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”).
| Method | Endpoint | Auth | Body | Success |
|---|---|---|---|---|
| POST | /api/register | — | name, email, password | 201 Register successfully |
| POST | /api/login | — | email, password | 200 { user, token } |
| GET | /api/admin/users | JWT | — | 200 users (newest first) |
| POST | /api/admin/users | JWT | name, email, password | 201 User created successfully |
| GET | /api/admin/users/:id | JWT | — | 200 { id, name, email } |
| PUT | /api/admin/users/:id | JWT | name, email, password | 200 User updated successfully |
| DELETE | /api/admin/users/:id | JWT | — | 200 User deleted successfully |
Error responses
| HTTP | When | Body |
|---|---|---|
| 422 | Validation failed | { success: false, message: "Validation error", errors: [{ path, msg, ... }] } |
| 401 | No token / invalid or expired token / wrong password | Unauthenticated. · Invalid token · Invalid password |
| 404 | Login with an unknown e-mail | User not found |
| 500 | Database 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
| Field | Type | Rule |
|---|---|---|
id | Int, auto increment | Primary key |
name | VarChar(255) | Required |
email | VarChar(255), unique | Required, valid format, not used by another user |
password | VarChar(255) | At least 6 characters, stored as a bcrypt hash |
createdAt · updatedAt | DateTime | Set automatically |
Frontend pages
| Route | Page | Access |
|---|---|---|
/ | Home | Public |
/register | Register | Guests (logged-in users go to the dashboard) |
/login | Login | Guests |
/admin/dashboard | Dashboard | Logged in |
/admin/users | User list | Logged in |
/admin/users/create | Add user | Logged in |
/admin/users/edit/:id | Edit user | Logged 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.
- The React code is the same as in local development — only the transport changes.
- mockApi.js mirrors every controller and validator: the same routes, status codes, messages and express-validator error format.
- Data is stored in the visitor’s browser (localStorage). Reset data in the demo banner restores the sample users.
- Demo login:
admin@demo.com/password. - Built and deployed automatically by GitHub Actions (
.github/workflows/pages.yml) withVITE_DEMO=true. A normal build contains no demo code.
Run locally
- Create a MySQL database named
db_express. - Copy
backend-express/.env.exampleto.envand setDATABASE_URLandJWT_SECRET. - Start the API (port 3000):
cd backend-express npm install npx prisma migrate dev node index.js
- 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
- The add and edit pages read the token when the request is sent (it used to be read once when the file loaded, so requests right after login had no token).
- The edit page sends the token when loading the user, so it also works when opened directly or refreshed.
backend-express/.envis no longer tracked; use.env.example.
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.