https://github.com/shaunevening/dockerized-express-postgres
Template repository for creating a dockerized TypeScript Express server with Postgres
https://github.com/shaunevening/dockerized-express-postgres
docker-compose express postgres template typescript
Last synced: 4 months ago
JSON representation
Template repository for creating a dockerized TypeScript Express server with Postgres
- Host: GitHub
- URL: https://github.com/shaunevening/dockerized-express-postgres
- Owner: ShaunEvening
- Created: 2019-08-04T15:40:51.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-11T01:41:08.000Z (over 3 years ago)
- Last Synced: 2025-10-24T01:32:37.837Z (8 months ago)
- Topics: docker-compose, express, postgres, template, typescript
- Language: TypeScript
- Homepage:
- Size: 246 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Express API Starter
Template repository for creating a Node.js + Express server with TypeScript
## Getting Started
For this project, were are using docker to contain the application.
```bash
# Build the docker container for the first time
docker-compose up --build
# Run the existed docker container
docker-compose up
# Tear down the docker container
docker-compose down
```
## Environment Variables
The express server expects a few environment variables to be included via a `dev.env` file.
Create this file in the root of your project with the following keys:
```
SERVER_PORT=8081
DATABASE_HOST="localhost"
DATABASE_USER="starter"
DATABASE_PASSWORD="starter-dev"
DATABASE_NAME="express-starter-db"
DATABASE_PORT=5432
```
**NOTE:** The variables above are what this starter expects out of the box.
## Database
This project is setup with a Docker Postgres image and uses pg for database migrations.
All files for this database are inside of the `./postgres` folder.
### Tables
To set up your database tables, add your sql scripts inside of the `./postgres/tables` folder. Once your files are in there, make sure to import them all in the `./posgres/deploy_tables.sql` script.
### Migrations
All migrations scripts can be found inside of the `./postgres/migrations` folder.
In the `package.json` there is a set of scripts for creating and running database migrations:
```bash
# Create a new migration file
yarn db:migrate-create
# Run all pending 'up' migrations
yarn db:migrate-up
# Run a single 'down' migration
yarn db:migrate-down
# Run N 'up' migrations
yarn db:migrate-up
# Run N 'down' migrations
yarn db:migrate-down
```
**NOTE:** these scripts must be run inside of the docker image's bash shell while it's running and can be accessed with the following command:
```bash
docker exec -it express-starter-api bash
```
### Entering the `psql` terminal
To make use of the psql terminal run the following command while the postgres container is running:
```bash
docker exec -it express-starter-postgres psql -U starter -d express-starter-db
```
## Available Endpoints
```
GET /v1/health - returns that the api is running
```