- JavaScript 69.7%
- HTML 11.2%
- Shell 9.4%
- Dockerfile 7.6%
- CSS 2.1%
| .forgejo/workflows | ||
| _blog | ||
| bin | ||
| client | ||
| deploy | ||
| server | ||
| test | ||
| .dockerignore | ||
| .gitignore | ||
| .jshintrc | ||
| app.js | ||
| Dockerfile | ||
| LICENSE | ||
| package-lock.json | ||
| package.json | ||
| readme.md | ||
PostgreSQL and NodeJS
This is a basic single page application built with Node, Express, Angular, and PostgreSQL.
Quick Start
- Clone the repo
- Install dependencies:
npm ci - Start Postgres and create a database called
todo - Create the database tables:
npm run init-db - Start the server:
npm start - Open http://localhost:3000
The connection defaults to postgres://localhost:5432/todo. Override it with
DATABASE_URL, or with the standard PGHOST, PGPORT, PGDATABASE, PGUSER,
and PGPASSWORD variables. TLS can be enabled with PGSSLMODE and
PGSSLROOTCERT.
Health endpoints:
GET /healthz- process is aliveGET /readyz- process can reach PostgreSQL
Tests
npm test
The tests use Node's built-in test runner and do not require a database. The original Apache Bench load test is still available:
sh test/load-test.sh
Docker
docker build -t node-postgres-todo:local .
docker run --rm -p 3000:3000 \
-e DATABASE_URL=postgres://user:password@host.docker.internal:5432/todo \
node-postgres-todo:local
The image runs as the non-root node user, uses tini as PID 1, and has a
health check against /healthz.
CI
.forgejo/workflows/ci.yml runs on Forgejo Actions:
- Installs dependencies, runs tests, and audits production dependencies.
- Builds and pushes an image tagged with the commit SHA and
latestto the Forgejo container registry. - Rewrites the image tag in
deploy/app/kustomization.yamlso Argo CD can roll out the exact commit.
Repository variables and secrets:
| Name | Kind | Purpose |
|---|---|---|
REGISTRY |
variable | Registry host, e.g. forgejo.example.com |
REGISTRY_USERNAME |
secret | Registry user |
REGISTRY_TOKEN |
secret | Registry password/token |
GITOPS_TOKEN |
secret (optional) | Token allowed to push the image tag commit |
Every job runs on the Forgejo runner labeled docker. That runner must have
Docker and Buildx available. If your runner uses a different label, update all
three runs-on entries in .forgejo/workflows/ci.yml.
Kubernetes / Argo CD
Everything needed to deploy the app, CloudNativePG, and the Redis operator lives
in deploy/. In short:
kubectl apply -f deploy/argocd/root-app.yaml
The root application creates two operator applications first and then the
application: CloudNativePG 1.30.2 (chart 0.29.2, namespace cnpg-system) and
redis-operator 0.27.0 (chart 0.27.0, namespace redis-operator). The app
namespace is todo.
See deploy/README.md for all placeholders that must be
replaced before applying.
Dependency notes
The project was updated from a 2016-era dependency set. The upgrades are safe,
but pg required a code change because the callback-based pg.connect() API
was removed in pg@8.
| Dependency | Was | Now | Notes |
|---|---|---|---|
| Node.js | unspecified | >=20 |
Tested with Node 22 (container) and 26 (local) |
| express | ~4.13.4 |
^4.22.3 |
Kept on 4.x on purpose; Express 5 is a separate breaking migration |
| pg | ^6.1.0 |
^8.23.1 |
Rewritten to use Pool and async/await |
| body-parser | ~1.15.1 |
^1.20.9 |
Kept on 1.x to match Express 4 |
| cookie-parser | ~1.4.3 |
^1.4.7 |
Compatible |
| debug | ~2.2.0 |
^4.4.3 |
Compatible |
| morgan | ~1.7.0 |
^1.12.1 |
Compatible |
| serve-favicon | ~2.3.0 |
^2.5.1 |
Compatible |
| jade | ~1.11.0 |
removed | Never used; views are static HTML |
| supervisor | not declared | removed | npm start now runs node ./bin/www; use npm run dev for reloads |
| supertest | none | ^7.3.2 |
Added for HTTP tests |
npm audit --omit=dev reports 0 vulnerabilities. The remaining available major
upgrades (Express 5, body-parser 2) are intentionally not applied. The Angular
1.5 client is loaded from a CDN and is unrelated to the server upgrade; moving
it forward would be a front-end rewrite.