A NestJS multi-protocol echo server that exposes HTTP, native WebSocket, Socket.IO, and embedded MQTT endpoints from a single application.
- HTTP root endpoint that returns
Hello World! - Native WebSocket echo server on the same HTTP port
- Socket.IO echo gateway on a dedicated configurable port
- Embedded MQTT broker powered by
aedes - MQTT support over TCP and WebSocket (
/mqtt) - Connection logging and welcome/response payloads for each protocol
- Global configuration support through
@nestjs/config
- NestJS
- TypeScript
@nestjs/configsocket.iowsmqttaedes- Jest
- Supertest
- Node.js
- npm
No external MQTT broker is required. The MQTT broker is embedded in the application.
npm installThe application works with defaults, but these optional variables are read at runtime:
| Variable | Default | Purpose |
|---|---|---|
PORT |
4500 |
HTTP server port and native WebSocket entry point |
SIO_PORT |
4502 |
Socket.IO server port |
MQTT_TCP_PORT |
1883 |
MQTT broker TCP port |
MQTT_REQUEST_TOPIC |
test/request |
Logged at startup only |
MQTT_RESPONSE_TOPIC |
test/response |
Logged at startup only |
[TODO: complete this section if you want to document deployment-specific variables or client-side configuration.]
npm run devThe application starts the HTTP server first, then attaches the native WebSocket server and the embedded MQTT broker automatically.
Use the following commands during development:
npm run dev
npm run start:debug
npm run format
npm run lintnpm run build
npm run start:prod- Main HTTP endpoint:
GET / - Native WebSocket:
ws://localhost:4500 - Socket.IO:
http://localhost:4502 - MQTT over TCP:
mqtt://localhost:1883 - MQTT over WebSocket:
ws://localhost:4500/mqtt - The default HTTP response is
Hello World! - Socket.IO listens for the
messageevent and returns anresponsepayload - Native WebSocket clients receive a
welcomemessage on connect and an echoedresponsefor each message - MQTT clients publish to any topic and receive an echoed message under
echo/<topic>
Basic request example:
curl http://localhost:4500/Expected response:
Hello World!
Swagger/OpenAPI documentation is not configured in this repository yet, so there is no /api docs route at the moment.
.
├── src
│ ├── app.controller.ts
│ ├── app.module.ts
│ ├── app.service.ts
│ ├── main.ts
│ ├── mqtt
│ │ ├── mqtt.module.ts
│ │ └── mqtt.service.ts
│ ├── socketio
│ │ ├── socketio.gateway.ts
│ │ └── socketio.module.ts
│ └── websocket
│ ├── websocket.module.ts
│ └── websocket.service.ts
├── test
│ └── app.e2e-spec.ts
├── package.json
└── docker-compose.yml
Swagger/OpenAPI is not set up in the current codebase.
[TODO: complete this section if you add @nestjs/swagger and expose a documentation route.]
npm run build- Compile the NestJS application intodist/npm run format- Format TypeScript sources with Prettiernpm run start- Start the application in normal modenpm run dev- Start the application in watch modenpm run start:debug- Start the application in watch mode with the debugger enablednpm run start:prod- Run the compiled production build fromdist/mainnpm run lint- Lint and auto-fix TypeScript files with ESLintnpm run test- Run the unit test suite with Jestnpm run test:watch- Run Jest in watch modenpm run test:cov- Generate a coverage reportnpm run test:debug- Run Jest under the Node.js inspectornpm run test:e2e- Run end-to-end tests
Run the automated tests with:
npm run testOther useful test commands:
npm run test:watch
npm run test:cov
npm run test:e2eThe current test coverage is minimal and focuses on the root controller plus a basic end-to-end check for GET /.
- Fork the repository.
- Create a feature branch.
- Make your changes.
- Run
npm run lintand the relevant tests. - Open a pull request with a clear description of the change.
This project is currently licensed as UNLICENSED.