A backend API project built with Node.js, TypeScript, Express, and PostgreSQL, using Docker Compose for local development and hot-reload in dev mode.
This repository demonstrates a modern, production-aligned setup with:
- ESM-based TypeScript
- Persistent Postgres storage via Docker volumes
- Auto-reloading development workflow
- Clean separation between application code and infrastructure
- Node.js (ES Modules)
- TypeScript
- Express
- PostgreSQL
- Docker & Docker Compose
- nodemon + ts-node (ESM loader) for dev hot reload
- Node.js version 18 or higher
- Docker and Docker Compose
- npm
Create a .env file in the project root.
DB_HOST=localhost
DB_PORT=3002
DB_USER=app_user
DB_PASSWORD=passw
DB_NAME=app_dbBuild the app and start the two containers in detached mode.
docker compose up -d --buildPostgreSQL will:
- Run in its own container
- Expose port
3002 - Persist data using a named Docker volume
The app will:
- Expose port
3001to localhost
To stop them without deleting data:
docker compose downnpm run devThis will:
- Watch files inside the
src/directory - Automatically restart the server on file changes
- Execute TypeScript directly using Node’s ESM loader
PostgreSQL data is stored in a Docker volume.
- Volume name:
pgdata - Mounted at:
/var/lib/postgresql(PostgreSQL 18+ compatible)
This ensures:
- Database data survives container restarts
- Moving or renaming the project directory does not affect the data
- Local development closely mirrors production architecture
GET /usersReturns a list of users stored in PostgreSQL.
docker exec -it node_ts_postgres psql -U app_user -d app_dbHost: localhost
Port: 3002
Database: app_db
User: app_user
Password: passw
List all Docker volumes:
docker volume lsInspect the Postgres volume:
docker volume inspect pgdataRemove unused Docker volumes:
docker volume prune