This project is now split into:
- Static frontend:
index-ultimate.html,styles-ultimate.css,script-enhanced.js - TypeScript backend:
backend/src/server.ts(Node + Express + PostgreSQL)
- Node.js (v18+ recommended)
- PostgreSQL running locally or in the cloud
Create a database and a user (example):
CREATE DATABASE expense_tracker;
CREATE USER expense_user WITH PASSWORD 'your-strong-password';
GRANT ALL PRIVILEGES ON DATABASE expense_tracker TO expense_user;Then create a .env file in the project root (same folder as package.json):
DATABASE_URL=postgres://expense_user:your-strong-password@localhost:5432/expense_tracker
PORT=4000The backend will automatically create the expenses table on first start.
From the project root (expense-tracker):
npm installFor development (auto‑reload with nodemon + ts-node):
Npm DEV runThe API and static frontend will be served from:
http://localhost:4000(index page)http://localhost:4000/api/expenses(REST API)
To build the backend to plain JavaScript and run it:
npm run build:backend
npm start- GET
/api/health– quick health check - GET
/api/expenses– list expenses (supportscategory,startDate,endDatequery params) - POST
/api/expenses– create a new expense- body:
{ description, amount, category, currency, date }
- body:
- GET
/api/expenses/stats– totals, average, highest, count - GET
/api/expenses/breakdown– totals per category
The frontend (script-enhanced.js) calls these endpoints to:
- Load and filter the expense list
- Show total/average/highest stats
- Render the category breakdown cards
- Add new expenses via the form