Simple NestJS application that bootstraps a reusable NATS connection using the official modern NATS.js Node transport package.
- NestJS HTTP application
- Global environment configuration using
@nestjs/config - Local NATS server with JetStream enabled using Docker Compose
- One shared NATS connection per NestJS application instance
- Core NATS service
- Demo service for see NATS behavior
- Basic health endpoint for checking NATS connection state
- Graceful shutdown hooks
- Unit tests for controller and service code
- ESLint setup
src/
├── modules/demos/core-nats/ # HTTP-triggered learning demos
├── modules/health/ # health endpoint
├── infrastructure/nats/ # reusable NATS connection + CoreNatsService
├── shared/interfaces/
└── shared/config
docker compose up -d
npm run start:devHealth check:
GET http://localhost:3000/health
Run all demos:
curl -X POST http://localhost:3000/demos/core-nats/allRun one demo:
curl -X POST http://localhost:3000/demos/core-nats/exact
curl -X POST http://localhost:3000/demos/core-nats/star
curl -X POST http://localhost:3000/demos/core-nats/greater-than
curl -X POST http://localhost:3000/demos/core-nats/fan-out
curl -X POST http://localhost:3000/demos/core-nats/at-most-onceQueue Group demo APIs:
curl -X POST http://localhost:3000/demos/core-nats/queue-group/jobs
curl -X POST http://localhost:3000/demos/core-nats/queue-group/jobs/batchNormal subscribers all receive one message. Queue Group subscribers using the same subject and demo-workers group compete, so each message is handled by one group member.
Tests are unit tests and do not require a real NATS server. Running the HTTP demos still requires NATS from Docker Compose.
npm test -- --runInBand
npm run lint
npm run buildCopy .env.example to .env if needed.