{"id":31078118,"url":"https://github.com/loftwah/demo-node-app","last_synced_at":"2025-10-25T10:40:41.152Z","repository":{"id":314088793,"uuid":"1054071260","full_name":"loftwah/demo-node-app","owner":"loftwah","description":"My demo node app","archived":false,"fork":false,"pushed_at":"2025-09-21T10:34:19.000Z","size":94,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-20T11:48:13.589Z","etag":null,"topics":["aws","aws-s3","crud","elasticache-redis","nodejs","rds-postgres"],"latest_commit_sha":null,"homepage":"https://blog.deanlofts.xyz","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/loftwah.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-10T10:21:44.000Z","updated_at":"2025-09-21T10:34:22.000Z","dependencies_parsed_at":"2025-09-10T15:38:50.490Z","dependency_job_id":"331f50fc-945d-436f-ae45-beceff803d97","html_url":"https://github.com/loftwah/demo-node-app","commit_stats":null,"previous_names":["loftwah/demo-node-app"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/loftwah/demo-node-app","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loftwah%2Fdemo-node-app","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loftwah%2Fdemo-node-app/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loftwah%2Fdemo-node-app/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loftwah%2Fdemo-node-app/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loftwah","download_url":"https://codeload.github.com/loftwah/demo-node-app/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loftwah%2Fdemo-node-app/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280943421,"owners_count":26417747,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-25T02:00:06.499Z","response_time":81,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","aws-s3","crud","elasticache-redis","nodejs","rds-postgres"],"created_at":"2025-09-16T08:03:54.966Z","updated_at":"2025-10-25T10:40:41.109Z","avatar_url":"https://github.com/loftwah.png","language":"TypeScript","readme":"## Loftwah's Demo Node App\n\nThis repository contains a minimal TypeScript Node.js 20 web application that demonstrates CRUD operations across S3, RDS Postgres, and ElastiCache Redis. It is packaged for both ECS and EKS from a single repository.\n\n### About me\n\nI am Loftwah. I build things, break things, and then document how to put them back together so we can ship faster next time. I write at [blog.deanlofts.xyz](https://blog.deanlofts.xyz). This repo is a compact demo I use to validate end to end integrations before committing to infrastructure decisions.\n\n### Endpoints\n\n- `GET /healthz` returns a JSON object with overall status and the status of S3, Postgres, and Redis.\n- S3 CRUD at `POST|GET|DELETE /s3/:id` storing objects at `s3://$S3_BUCKET/app/\u003cid\u003e.txt`.\n- Postgres CRUD at `POST|GET|PUT|DELETE /db/items[/:id]` with a table schema `items(id uuid, name text, value jsonb, created_at timestamptz)`.\n- Redis CRUD at `POST|GET|PUT|DELETE /cache/:key`.\n- `GET /selftest` runs a one-off self-test that exercises CRUD across all three services and returns a summary.\n\n### Authentication\n\nIf no `Authorization` header is provided, the request is treated as if made by user `loftwah`. The `Authorization` values `Bearer demo` or `loftwah:hunter2` are also accepted and set the user to `loftwah`.\n\n### Self-test\n\nAt startup, the app can run an automated self-test that:\n\n- Writes, reads, and deletes an S3 object in bucket `$S3_BUCKET`.\n- Creates, reads, updates, and deletes a Postgres row in the `items` table.\n- Sets, gets, and deletes a Redis key.\n\nEnable or disable:\n\n- Environment variable `SELF_TEST_ON_BOOT=true|false`. Default is `true`.\n\nRun on demand:\n\n```bash\ncurl -s http://\u003chost\u003e:3000/selftest | jq\n```\n\nLogs:\n\n- The app logs each self-test step with tags `[selftest][s3]`, `[selftest][db]`, and `[selftest][redis]`, and a final summary.\n\n### Local Development with Docker Compose\n\n1. Start the stack.\n\n```bash\ndocker compose up --build -d\n```\n\n2. Verify health.\n\n```bash\ncurl -s localhost:3000/healthz | jq\n```\n\n3. Exercise CRUD locally.\n\n```bash\n# S3\ncurl -s -X POST localhost:3000/s3/banana -H 'Content-Type: application/json' -d '{\"text\":\"hello from Loftwah\"}' | jq\ncurl -s localhost:3000/s3/banana\ncurl -s -X DELETE localhost:3000/s3/banana | jq\n\n# Postgres\ncurl -s -X POST localhost:3000/db/items -H 'Content-Type: application/json' -d '{\"name\":\"banana\",\"value\":{\"tasty\":true}}' | tee /tmp/item.json; echo\nID=$(jq -r .id /tmp/item.json)\ncurl -s localhost:3000/db/items | jq\ncurl -s localhost:3000/db/items/$ID | jq\ncurl -s -X PUT localhost:3000/db/items/$ID -H 'Content-Type: application/json' -d '{\"name\":\"banana-2\",\"value\":{\"updated\":true}}' | jq\ncurl -s -X DELETE localhost:3000/db/items/$ID | jq\n\n# Redis\ncurl -s -X POST localhost:3000/cache/greeting -H 'Content-Type: application/json' -d '{\"value\":\"hello loftwah\"}' | jq\ncurl -s localhost:3000/cache/greeting\ncurl -s -X PUT localhost:3000/cache/greeting -H 'Content-Type: application/json' -d '{\"value\":\"yo loftwah\"}' | jq\ncurl -s -X DELETE localhost:3000/cache/greeting | jq\n```\n\n### Running without Docker Compose\n\n```bash\nnpm ci\nnpm run build\nnpm start\n```\n\n### Docker Build and Run\n\n```bash\ndocker build -t demo-node-app:local .\ndocker run --rm -p 3000:3000 \\\n  -e APP_ENV=local -e LOG_LEVEL=debug -e PORT=3000 \\\n  -e S3_BUCKET=local-bucket -e AWS_REGION=us-east-1 \\\n  -e DB_HOST=host.docker.internal -e DB_PORT=5432 -e DB_USER=postgres -e DB_PASS=postgres -e DB_NAME=app -e DB_SSL=disable \\\n  -e REDIS_HOST=host.docker.internal -e REDIS_PORT=6379 \\\n  -e SELF_TEST_ON_BOOT=false \\\n  demo-node-app:local\n```\n\n### ECS Buildspec\n\nThe file `buildspec.yml` builds the TypeScript code, builds and pushes a Docker image tagged with `staging` and with the current git commit SHA, and emits an `imagedefinitions.json` file for ECS deployment.\n\n### CI with GitHub Actions (optional)\n\nThe workflow at `.github/workflows/ci.yml` runs on pull requests and pushes to `main`. It performs type checking and builds the project. If a `GHCR_PAT` secret is configured, it also builds and pushes a Docker image to GitHub Container Registry (GHCR) using the tags `staging` (on `main`) and the short git SHA.\n\nNote: Deployment to AWS is handled by CodePipeline/CodeBuild/CodeDeploy using `buildspec.yml`. The GitHub Actions workflow is build-only and optional.\n\n### EKS Helm Chart\n\nThe Helm chart in `deploy/eks/chart` deploys the application with a Deployment, Service, Ingress for ALB, and a Secret. Set `image.repository` in `values.yaml` to your ECR repository. Configure database and Redis endpoints and secrets in `values.yaml`.\n\n### Helm values stub\n\nUse `deploy/eks/chart/values-stub.yaml` as a starting point. It includes prefilled known values and TODOs for RDS and ElastiCache. Example usage:\n\n```bash\nhelm upgrade --install demo-node-app deploy/eks/chart \\\n  --namespace demo --create-namespace \\\n  -f deploy/eks/chart/values-stub.yaml\n```\n\n### Configuration\n\n- `APP_ENV` (default `staging`), `LOG_LEVEL`, `PORT`\n- `S3_BUCKET`, `AWS_REGION`\n- `DB_HOST`, `DB_PORT`, `DB_USER`, `DB_PASS`, `DB_NAME`, `DB_SSL` (required or disable)\n- `REDIS_HOST`, `REDIS_PORT`, `REDIS_PASS`\n- `SELF_TEST_ON_BOOT` (default `true`)\n\n### OpenTelemetry Tracing\n\nThis app includes basic OpenTelemetry auto-instrumentation for HTTP/Express, Postgres (`pg`), and Redis (`ioredis`). Configure these env vars to export traces:\n\n- `OTEL_SERVICE_NAME` (default `demo-node-app`)\n- `OTEL_EXPORTER_OTLP_ENDPOINT` (default `http://otel-collector.observability:4318`)\n- Optional: `OTEL_EXPORTER_OTLP_HEADERS` (e.g., `Authorization=Bearer \u003ctoken\u003e`)\n\nKubernetes with the included Collector:\n\n```\nkubectl apply -f aws-labs/kubernetes/manifests/otel-collector-gateway.yml\n```\n\nEnsure your Deployment or container env sets `OTEL_EXPORTER_OTLP_ENDPOINT` to the Collector service (above default works when running in-cluster).\n\n### Domains\n\n- ECS: `demo-node-app-ecs.aws.deanlofts.xyz`\n- EKS: `demo-node-app-eks.aws.deanlofts.xyz`\n\n### AWS Validation Steps\n\nThe following outline demonstrates that each service is used in AWS. Replace placeholders with actual values or export them as environment variables.\n\n1. S3 validation on AWS\n\n- Ensure the task or pod has access to S3 and that `S3_BUCKET` is set to an existing bucket.\n- Run curl against the service to write, read, and delete an object.\n\n```bash\ncurl -s -X POST https://\u003cdomain\u003e/s3/demo -H 'Content-Type: application/json' -d '{\"text\":\"hello from Loftwah on AWS\"}'\ncurl -s https://\u003cdomain\u003e/s3/demo\ncurl -s -X DELETE https://\u003cdomain\u003e/s3/demo\n```\n\n2. RDS Postgres validation on AWS\n\n- Point `DB_HOST`, `DB_PORT`, `DB_USER`, `DB_PASS`, `DB_NAME`, `DB_SSL` to your RDS instance.\n- Use curl to create, read, update, and delete an item.\n\n```bash\ncurl -s -X POST https://\u003cdomain\u003e/db/items -H 'Content-Type: application/json' -d '{\"name\":\"aws-item\",\"value\":{\"cloud\":true}}' | tee /tmp/aws-item.json\nID=$(jq -r .id /tmp/aws-item.json)\ncurl -s https://\u003cdomain\u003e/db/items/$ID\ncurl -s -X PUT https://\u003cdomain\u003e/db/items/$ID -H 'Content-Type: application/json' -d '{\"name\":\"aws-item-2\",\"value\":{\"updated\":true}}'\ncurl -s -X DELETE https://\u003cdomain\u003e/db/items/$ID\n```\n\n3. ElastiCache Redis validation on AWS\n\n- Point `REDIS_HOST`, `REDIS_PORT`, and `REDIS_PASS` to your Redis endpoint.\n- Use curl to set, get, and delete a key.\n\n```bash\ncurl -s -X POST https://\u003cdomain\u003e/cache/ping -H 'Content-Type: application/json' -d '{\"value\":\"hello aws\"}'\ncurl -s https://\u003cdomain\u003e/cache/ping\ncurl -s -X DELETE https://\u003cdomain\u003e/cache/ping\n```\n\n### Proving usage\n\n- S3 usage is proven by successful write, read, and delete of objects via the `/s3` endpoint path.\n- RDS usage is proven by creating the `items` table on boot if it does not exist and by CRUD operations via the `/db/items` endpoints.\n- Redis usage is proven by successful set, get, and delete operations via the `/cache` endpoints and by the application health check ping.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floftwah%2Fdemo-node-app","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floftwah%2Fdemo-node-app","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floftwah%2Fdemo-node-app/lists"}