Skip to main content

Examples

Minimal, self-contained example apps live in the examples/ folder of the repository. Most examples use the PGLite driver with a file-backed data directory under the repo-root tmp/ folder, so nothing external needs to be installed or started — no Docker, no database server. The two PostgreSQL examples connect to a real PostgreSQL server instead (they need the pg peer dependency and a DATABASE_URL). Each folder is a workspace package that resolves @portqueue/* straight from the repo.

ExampleDriverWhat it shows
dashboard-node-serverPGLiteServe the dashboard from a plain node:http server
dashboard-expressPGLiteMount the dashboard as Express middleware alongside your own routes
job-schedulingPGLiteDelayed (one-off) and recurring (interval + cron) jobs — see Delayed & recurring jobs
retries-backoffPGLiteRetries with fixed/exponential backoff and jitter — see Retries & backoff
idempotency-singletonPGLiteidempotencyKey and singletonKey deduplication — see Producing jobs
graceful-shutdownPGLiteDraining in-flight handlers via job.signal on shutdown
postgresql-connectionPostgreSQLConnect to a real PostgreSQL server with DATABASE_URL
transactional-enqueuePostgreSQLEnqueue a job atomically with your own DB write — see Transactions

Running​

From the repo root. Every launcher rebuilds @portqueue/core and @portqueue/dashboard first, so an example always runs the code in your working tree rather than a stale dist/ — set PORTQUEUE_SKIP_BUILD=1 to skip that when you haven't touched any package source. Each example has a root npm run example:* script; if you prefer, there's an equivalent shell script under scripts/dev/examples/ that does the same thing (some devs like running the .sh versions directly):

npm run example:dashboard-node # http://127.0.0.1:4321/portqueue
./scripts/dev/examples/dashboard-node-server.sh

npm run example:dashboard-express # http://127.0.0.1:4322/portqueue
./scripts/dev/examples/dashboard-express.sh

npm run example:schedule-delayed
./scripts/dev/examples/job-scheduling-delayed.sh

npm run example:schedule-recurring
./scripts/dev/examples/job-scheduling-recurring.sh

npm run example:retries
npm run example:idempotency
npm run example:graceful

The two PostgreSQL examples need a reachable database that already exists — set DATABASE_URL first:

DATABASE_URL=postgres://user:pass@localhost:5432/app npm run example:postgresql
DATABASE_URL=postgres://user:pass@localhost:5432/app npm run example:transactional

Or run an example directly from its folder with npm start (dashboards, retries, idempotency, graceful, and the PostgreSQL examples) / npm run delayed / npm run recurring (job-scheduling).