This is a Node.js + Express application for buses in Leeds, allowing authenticated users to view, create, update, and delete data regarding bus stops and arrival logs.
- Runtime: Node.js
- Framework: Express
- Database: PostgreSQL (
pg)
- User login and registration
- Create, read, update, and delete stops/logs with ease
- Get reliability statistics for stops/services
Create a .env file at project root with the required keys:
PORT=3000
DB_USER=your_db_user
DB_PASSWORD=your_db_password
DB_HOST=your_db_host
DB_PORT=5432
DB_NAME=your_db_name
JWT_SECRET=your_jwt_secret
DB_SSL=falseNotes:
DB_SSLcan betrueorfalse.- In
db/index.js, SSL is auto-enabled when host containsrender.comunlessDB_SSL=false. - Do not commit real secrets (DB password, JWT secret) to source control.
- Install dependencies:
npm install
- Configure
.env. - Start development server:
npm run dev
- If
npm run devfails, use production start:npm start
- Local URLs:
- App/UI:
http://localhost:3000 - API base:
http://localhost:3000/api
- App/UI:
Use the SQL below to create the minimum tables required by this project.
-- Users for authentication
CREATE TABLE IF NOT EXISTS users (
id SERIAL PRIMARY KEY,
username VARCHAR(100) UNIQUE NOT NULL,
password_hash TEXT NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW()
);
-- Bus stops table
CREATE TABLE stops (
atco_code VARCHAR(20) PRIMARY KEY,
stop_name VARCHAR(255) NOT NULL,
street VARCHAR(255),
indicator VARCHAR(50),
latitude DECIMAL(9,6) NOT NULL,
longitude DECIMAL(9,6) NOT NULL,
locality VARCHAR(100)
);
-- Arrival logs table
CREATE TABLE arrival_logs (
id SERIAL PRIMARY KEY,
stop_id VARCHAR(20) NOT NULL REFERENCES stops(atco_code),
route_number VARCHAR(10) NOT NULL,
scheduled_time TIMESTAMP NOT NULL,
actual_time TIMESTAMP,
delay_minutes INTEGER,
status VARCHAR(20)
);The repository includes two CSV seeding scripts:
- Script:
scripts/importLeedsStops.js - Source CSV:
data/450Stops.csv - Behavior:
- imports rows where
ParentLocalityName === 'Leeds' - inserts into
stops - ignores duplicates by
atco_code(ON CONFLICT DO NOTHING)
- imports rows where
- Dataset obtained from https://beta-naptan.dft.gov.uk/download/la
Run:
node scripts/importLeedsStops.js- Script:
scripts/importArrivalLogs.js - Source CSV:
data/arrival_logs.csv - Behavior:
- inserts logs into
arrival_logs - treats empty
actual_timeanddelay_minutesasnull - prints progress every 1000 rows
- inserts logs into
- Data generated synthetically from Google Gemini
Run:
node scripts/importArrivalLogs.jsRecommended import order:
- stops first (
importLeedsStops.js) - logs second (
importArrivalLogs.js)
Prerequisites:
- PostgreSQL tables must already exist.
.envdatabase credentials must point to the target DB.
This API is hosted on Render.
Public URLs:
https://cwk1.onrender.comhttps://cwk1.onrender.com/api
- PDF:
docs/API_Documentation.pdf - Markdown:
docs/API_Documentation.md
The PDF includes:
- all available endpoints
- parameters and request formats
- expected JSON responses
- authentication process
- error/status codes
/api/auth/api/stops/api/logs/api/reliability