A minimal "Hello World" web application using Node.js with the Fastify v5 framework, containerized with Docker, and integrated with OpenSearch v3 User Behavior Insights (UBI) plugin.
project-root/
├── app/
│ ├── index.js # Main Fastify application
│ ├── package.json # Node.js dependencies
│ └── ubiClient.js # OpenSearch UBI client
├── Dockerfile # Docker configuration for the app
├── docker compose.yml # Multi-service Docker setup
└── README.md # This file
- Fastify v5 Web Server: Latest version of the lightweight and fast web framework
- Hello World Endpoint: GET
/returns{ message: "Hello World" } - OpenSearch v3 Integration: Sends UBI events to the latest OpenSearch version
- Docker Containerization: Both app and OpenSearch run in containers
- Health Checks: Built-in health monitoring for services
GET /- Returns Hello World message and logs a UBI eventGET /health- Health check endpointGET /opensearch-status- Check OpenSearch connection status
This project uses the latest versions:
- Fastify v5: Latest major version with improved performance and ESM support
- OpenSearch v3: Latest version with enhanced features and performance improvements
- Node.js 20+: Required for Fastify v5 compatibility
- OpenSearch Client v3: Latest JavaScript client for OpenSearch v3
- Docker and Docker Compose installed on your system
- At least 2GB of available RAM (for OpenSearch v3)
- Node.js 20+ (if running locally without Docker)
# Clone or navigate to the project directory
cd /path/to/your/project
# Build and start all services
docker compose up --build
# Or run in detached mode
docker compose up --build -dCheck if services are running:
docker compose psTest the Hello World endpoint:
curl http://localhost:3000/
# Expected response: {"message":"Hello World"}Check application health:
curl http://localhost:3000/healthVerify OpenSearch connection:
curl http://localhost:3000/opensearch-statusCheck OpenSearch is accessible:
curl http://localhost:9200Check OpenSearch cluster health:
curl http://localhost:9200/_cat/healthView UBI events (after accessing the / endpoint):
curl http://localhost:9200/ubi-events/_search?prettyOpenSearch Dashboards is available at: http://localhost:5601
- Application Startup: The Fastify app starts and waits for OpenSearch to be ready
- UBI Integration: When the
/endpoint is accessed, the app:- Returns the Hello World message
- Sends a mock UBI event to OpenSearch
- Event Logging: UBI events are stored in the
ubi-eventsindex in OpenSearch
{
"timestamp": "2025-07-22T10:30:00.000Z",
"user_id": "user123",
"session_id": "session456",
"action": "page_view",
"object_type": "web_page",
"object_id": "hello_world_page",
"query": null,
"position": null,
"metadata": {
"page": "/",
"user_agent": "fastify-app/1.0.0",
"message": "Hello World page accessed"
}
}The following environment variables can be configured:
PORT: Application port (default: 3000)HOST: Application host (default: 0.0.0.0)OPENSEARCH_URL: OpenSearch endpoint (default: http://opensearch:9200)OPENSEARCH_USERNAME: OpenSearch username (default: admin)OPENSEARCH_PASSWORD: OpenSearch password (default: admin)
- Install dependencies:
cd app
npm install- Start OpenSearch separately:
docker compose up opensearch -d- Run the application:
cd app
OPENSEARCH_URL=http://localhost:9200 npm startView application logs:
docker compose logs app -fView OpenSearch logs:
docker compose logs opensearch -fView all service logs:
docker compose logs -f# Stop all services
docker compose down
# Stop and remove volumes (clears OpenSearch data)
docker compose down -v- Port conflicts: Make sure ports 3000, 9200, and 5601 are not in use
- Memory issues: OpenSearch requires at least 2GB RAM
- Connection timeouts: Wait for health checks to pass before testing
# Check if containers are running
docker ps
# Check service health
docker compose ps
# View container logs
docker compose logs [service-name]# Stop all services and remove volumes
docker compose down -v
# Remove images (optional)
docker compose down --rmi all
# Rebuild and restart
docker compose up --build- Implement real user authentication for UBI events
- Add more sophisticated UBI event types
- Configure OpenSearch security
- Add monitoring and alerting
- Implement proper logging and error handling
- Explore Fastify v5's new features like ESM support and improved TypeScript integration
- Leverage OpenSearch v3's enhanced performance and new features