Skip to content

This repository offers a detailed template for establishing a server with Express, complete with all essential dependencies to guarantee a seamless development process. The template is structured to uphold the modular monolith architecture, fostering a tidy and sustainable code structure.

Notifications You must be signed in to change notification settings

perceptronbd/server-template

Repository files navigation

TypeScript Express Server Template

A modern server template built with Express.js, TypeScript, PostgreSQL, and Prisma, featuring hot-reloading for development.

Prerequisites

  • Docker (Install)
  • Docker Compose (Install)
  • Node.js (optional, for local development)
  • Git

Installation

  1. Clone the repository:

    git clone https://github.com/your-username/server-template.git
    cd server-template
  2. Set up environment variables:

    cp .env.example .env  # Update values as needed
  3. Build and start the services:

    docker-compose up --build
    • This starts:
      • Express app on http://localhost:5001
      • PostgreSQL on port 5432

Development Workflow

Start the app

docker-compose up  # Use `-d` to run in background

Stop the app

docker-compose down

Hot-reloading

  • Edit files locally → changes auto-refresh in the container
  • TypeScript compilation happens automatically

Database Management with Prisma

  1. Generate Prisma Client:

    docker-compose exec app npx prisma generate
  2. Run Migrations:

    docker-compose exec app npx prisma migrate dev
  3. View Database with Prisma Studio:

    docker-compose exec app npx prisma studio

Add a new dependency

  1. Install inside the container (updates package.json):
    docker-compose exec app npm install <package-name>
  2. Commit the updated package.json and package-lock.json

Access Services

Service URL/Port
Express App http://localhost:5001
PostgreSQL Port: 5432
Prisma Studio http://localhost:5555

TypeScript Configuration

  • Strict type checking enabled
  • Path aliases configured
  • ESLint and Prettier integration
  • No any type allowed

Collaboration Guide

  1. Pull the latest changes:

    git pull origin main
  2. Rebuild containers (if dependencies change):

    docker-compose down && docker-compose up --build
  3. Branching workflow:

    • Create a feature branch:
      git checkout -b feat/your-feature
    • Commit changes:
      git add .
      git commit -m "Description"
      git push origin feat/your-feature
    • Create a Pull Request (PR) on GitHub

Troubleshooting

  • "Module not found" error:

    docker-compose down && docker-compose up --build
  • Database connection issues:

    • Check if PostgreSQL container is running
    • Verify database credentials in .env
    • Use db as the hostname in your connection string
  • Hot-reload not working:

    • Ensure ts-node-dev is in devDependencies
    • Check volume mounts in docker-compose.yml
  • Port conflicts:

    • Stop local PostgreSQL service if running
    • Modify port mappings in docker-compose.yml

License

MIT License. See LICENSE for details.


Happy Coding!

About

This repository offers a detailed template for establishing a server with Express, complete with all essential dependencies to guarantee a seamless development process. The template is structured to uphold the modular monolith architecture, fostering a tidy and sustainable code structure.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •