A small web GUI and backend API for managing an EV charging station network. This repository contains a static frontend (HTML/CSS/JS) and a Node.js backend that exposes generic CRUD endpoints for database tables and a few custom endpoints for common operations.
index.html,script.js,style.css— simple frontend UI (static files) located at the repo root.backend/— Node.js backend that serves JSON APIs and connects to a MySQL database.server.js— Express server exposing generic CRUD and special endpoints.db_config.js— MySQL connection helper (update credentials as needed).
- Frontend: plain HTML/CSS/JavaScript
- Backend: Node.js, Express
- Database: MySQL (the server expects a MySQL database named
ev_charging_station_networkby default)
- Generic CRUD endpoints for common tables (see
server.jstable list). - Special endpoints:
GET /api/total_spent/:uid— returns total spent for a user (calls the DB functionget_total_spent).GET /api/user_history/:uid— returns a user's history (calls stored procedureget_user_history).POST /api/charging_session_insert— convenience insert endpoint forcharging_session(DB trigger can compute cost).GET /api/schema/:table— returns column names for a table (useful for dynamic UIs).
- Node.js (v14+ recommended)
- npm (comes with Node.js)
- MySQL server
-
Clone the repo and open the project folder.
-
Install dependencies for the backend:
cd backend
npm install- Configure MySQL credentials:
- Update
backend/db_config.js(orbackend/server.jswhere the pool is created) with your MySQL username/password and database name. Example fields to update:host,user,password,database
- Create the database and tables.
This project assumes a MySQL database named ev_charging_station_network (or whatever you set in the config). There is no SQL schema file in this repo; import or create the schema you used when building the system (tables referenced in server code include: user, user_payment, vehicle, charging_station, station_facility, charger, maintenance, charging_session, services, userinformation, uservehiclestation).
Example to create an empty DB (you'll need to add the proper CREATE TABLE statements separately):
CREATE DATABASE ev_charging_station_network;
USE ev_charging_station_network;
-- Then create tables and stored procedures/functions used by the backend- Start the backend server:
cd backend
npm startThe server listens on port 3000 by default. You should see "🚀 Server running on port 3000" in the console.
- Open the frontend
- The frontend is static. Open
index.htmlin a browser (double-click or use a simple static server). The UI expects the backend API athttp://localhost:3000.
The backend implements generic REST-style endpoints for each table listed in server.js.
- GET /api/ — list all rows
- GET /api/
- POST /api/
- PUT /api/
- DELETE /api/
- GET /api/total_spent/:uid
- GET /api/user_history/:uid
- POST /api/charging_session_insert
- GET /api/schema/:table
- The generic CRUD handlers assume a simple primary-key pattern (the first column returned by
SHOW COLUMNS). If your tables use composite keys or different PK names, adjustserver.jsor add table-specific routes. - Some behavior depends on stored procedures, functions and/or triggers (e.g.,
get_total_spent,get_user_history, and any trigger that computes cost for charging sessions). Ensure those are created in the DB. - Do not keep plaintext credentials in source for production. Use environment variables or a secrets manager.
- For small local testing, the credentials in
backend/db_config.jsor the pool config inserver.jscan be modified directly. - Feel free to open issues or submit PRs. If you add a DB schema SQL file or seed data, include it under
backend/schema/and update this README with instructions to import it. ECONNREFUSEDwhen connecting to MySQL: ensure MySQL is running and credentials indb_config.js/server.jsare correct.CALL get_user_historyorSELECT get_total_spenterrors: make sure the corresponding stored procedure/function exists in the database.
Special endpoints:
Notes:
This project currently has no license file. Add a LICENSE if you want to open-source it under a specific license.
Contact: repository owner (khousalya)