A real-time gold investment web application built with Node.js and Server-Sent Events (SSE).
- Live Gold Price — Real-time gold price updates streamed to the browser via SSE
- Buy Gold — Submit investment orders through a simple form
- Connection Status — Visual indicator showing live connection (🟢) or disconnection (🔴)
- Event-Driven Architecture — Uses Node.js
EventEmitterfor internal communication
| Layer | Technology |
|---|---|
| Backend | Node.js (vanilla HTTP server) |
| Frontend | HTML, CSS, vanilla JavaScript |
| Real-time | Server-Sent Events (SSE) |
| Architecture | Event-driven, no frameworks |
GoldDigger/
├── public/
│ └── index.js # Client-side JS (SSE listener, form handling)
├── handlers/
│ └── routeHandlers.js # Route handlers (GET, POST, SSE)
├── events/
│ └── livePriceEvents.js # EventEmitter for price updates
├── utils/
│ ├── getData.js # Utility to fetch gold price data
│ └── sendResponse.js # Utility to send HTTP responses
├── server.js # Main server entry point
├── package.json
└── README.md
- Node.js (v18 or higher recommended)
git clone https://github.com/your-username/GoldDigger.git
cd GoldDigger
npm installnpm startThe server will start and you can access the app at http://localhost:8000 (or whichever port is configured).
| Method | Endpoint | Description |
|---|---|---|
GET |
/api |
Returns current gold price data |
POST |
/api |
Submit a gold purchase order |
GET |
/api/live |
SSE stream for real-time price updates |
{
"time": "2026-03-06T12:00:00.000Z",
"paidMoney": "500",
"goldPrice": 1850.75,
"sold": 0.27
}- SSE Connection — The client opens an
EventSourceconnection to/api/live, receiving gold price updates every 3 seconds. - Live Price Display — Each SSE message updates the displayed price and connection status in the browser.
- Buy Gold — The user enters an investment amount and submits the form. The client sends a
POSTrequest with the current price, timestamp, and calculated gold amount. - Event Emitter — On the server, the POST handler emits a
price-updatedevent for further processing.