PowerMonitor API is a backend service for monitoring, collecting, and analyzing power consumption and availability data. Built with NestJS and TypeScript, it provides RESTful endpoints for retrieving and managing power, voltage, amperage, and energy metering data, as well as system and calibration information.
- Collects and stores power, voltage, amperage, and energy metering data
- Provides daily, monthly, and yearly statistics on power consumption and availability
- Supports calibration coefficients and system information endpoints
- Scheduled tasks for data cleanup and maintenance
- JWT-based authentication and role-based access control
- MQTT integration for real-time data
- Logging with Winston
- Real-time updates via WebSockets (Socket.IO)
- Receives serial data frames from the monitoring board over a serial port, e.g.:
{ "type": "data", "voltage": 220.0, "current": 5.0, "frequency": 50.0 }
- Centralized logging to Elasticsearch (via Winston Elasticsearch transport)
- Application Performance Monitoring with Elastic APM (elastic-apm-node)
src/modules/
– NestJS modules, grouping related controllers and servicessrc/entities/
– TypeORM entities (database models)src/common/
– Shared DTOs, models, interfaces, and utilitiessrc/migrations/
– Database migration scriptssrc/constants.ts
– Application-wide constantssrc/environments.ts
– Environment configurationsrc/main.ts
– Application entry pointtests/
– Unit tests (Mocha + Chai)
- Node.js (v20+ recommended)
- npm
- PostgreSQL database
- Clone the repository:
git clone <repo-url> cd PowerMonitor.API
- Install dependencies:
npm install
- Configure environment variables:
- Copy
development.env
orproduction.env
and update with your settings.
- Copy
- Configure your PostgreSQL connection in
src/ormconfig.ts
or via environment variables. - Run migrations if needed.
- Development mode:
npm run start:dev
- Production build:
npm run build npm run start:prod
- Power data:
/api/power/*
- Power consumption:
/api/power-consumption/*
- Services/system info:
/api/services/*
- WebSocket real-time data: Socket.IO endpoint at
/socket.io/
Most endpoints require JWT authentication.
npm run build
– Build for productionnpm run package
– Lint, version bump, replace build, and compilenpm run build-dev
– Build in development modenpm run start
– Run with ts-nodenpm run start:dev
– Start in watch/dev modenpm run start:prod
– Run the production buildnpm run start:debug
– Run in debug modenpm run lint
– Lint the codebasenpm run format
– Format code with Prettiernpm run test
– Execute unit tests (Mocha + ts-node)npm run coverage
– Generate code coverage report
Copyright (c) 2025 Serhiy Krasovskyy xhunter74@gmail.com