A minimal online bookstore demo with a Node.js + Express backend and a Vite-based frontend.
This repository contains a full-stack example application named BookStore. The backend provides REST APIs for authentication, users, books, categories and payments. The frontend is a lightweight Vite-powered static client that consumes those APIs.
The frontend uses a simple render-then-init pattern: the router chooses a page, the page returns markup, and a separate init function attaches event listeners after the DOM is in place.
flowchart TD
A[URL changes] --> B[LoadPage in router.js]
B --> C{Route}
C -->|login| D[Render login layout]
C -->|profile| E[Render profile layout]
C -->|admin| F[Render admin layout]
C -->|home| G[Render home layout]
D --> H[Set app.innerHTML]
E --> H
F --> H
G --> H
H --> I[Run init functions]
I --> J[Attach events]
J --> K[User clicks button]
K --> L[Open modal, navigate, fetch data]
- Backend: Node.js, Express, Mongoose (MongoDB)
- Frontend: Vite, vanilla JS, Tailwind (minimal)
- Dev tooling: nodemon, Jest, Supertest
- backend/ — Express API server and related code
- book_store/ — Vite frontend application (static client)
Prerequisites:
- Node.js (v18+ recommended)
- npm
- MongoDB (local or remote)
- Backend
Install dependencies and start the API server:
cd backend
npm install
# development with auto-reload
npm run dev
# or start production-like server
npm run runServer defaults to port 9000 unless PORT is set.
- Frontend
Install and run the Vite dev server:
cd book_store
npm install
npm run devThe frontend runs via Vite and will proxy or call your backend API endpoints as configured in the client code.
Place environment variables in one of these locations (the project checks them in order):
backend/envs/.env.local(development)backend/envs/.env.prod(production)backend/.env
Common variables used by the project:
DB_URI/DB_URL— full MongoDB connection URI (overrides host/name)HOST— MongoDB host (default: localhost)DB_NAME— Database name (default: BookStore)PORT— API server port (default: 9000)JW_SECRET/JWT_SECRET— JWT signing secretJW_EXPIRES_IN/JWT_EXPIRES_IN— JWT expiration (e.g. 1d)
- Backend
npm run dev— startnodemondevelopment servernpm run run— start node servernpm test— run tests (Jest)
- Frontend (book_store)
npm run dev— start Vite dev servernpm run build— build for productionnpm run preview— preview build
The backend includes a convenience script to create a default admin user:
cd backend
node src/scripts/createAdmin.jsThis script creates an admin with username admin and a default password (see script). Use it only for local development.
Backend tests use Jest + Supertest. From the backend folder run:
npm testContributions are welcome. Open an issue to propose changes or submit a pull request with a clear description of your changes and rationale.
This project is provided under the ISC license (see LICENSE file).
If you'd like, I can also:
- add a short API reference section with common endpoints,
- add example
.env.localtemplate inbackend/envs/.env.local.example, or - create a short CONTRIBUTING.md with contribution guidelines.