A production-ready TypeScript backend boilerplate with Docker, Nginx, and comprehensive tooling. Whenever you need to set up a backend with TypeScript following standard industry practices, you can use this repository as a base or reference.
Itβs structured in a clean, scalable, and production-ready way β including proper folder organization, TypeScript configuration, and best practices for maintainability and performance.
- TypeScript - Type-safe backend development
- Express.js - Fast and minimal web framework
- Docker - Containerized deployment
- Nginx - Reverse proxy and load balancing
- Database Migrations - Schema version control
- Code Quality Tools - ESLint, Prettier, Husky
- Hot Reload - Development with Nodemon
Before you begin, ensure you have the following installed:
- Node.js (v16 or higher)
- npm or yarn
- Docker (optional, for containerized deployment)
- PostgreSQL or your preferred database
git clone https://github.com/HardCoder404/TS-Backend-Production-Setup.git
cd TS-Backend-Production-Setupnpm installCreate environment files based on your deployment environment:
Create a .env.development file in the root directory:
# General
ENV=development #production
PORT=3000
SERVER_URL=http://localhost:3000
# Database
DATABASE_URL=""
# Migration
MIGRATE_MONGO_URI="" # Same as database url
MIGRATE_AUTOSYNC="true" # falseCreate a .env.production file in the root directory:
# General
ENV=development #production
PORT=3000
SERVER_URL=http://localhost:3000
# Database
DATABASE_URL=""
# Migration
MIGRATE_MONGO_URI="" # Same as database url
MIGRATE_AUTOSYNC="true" # false
β οΈ Important: Never commit.envfiles to version control. They are already in.gitignore.
Start the development server with hot reload:
npm run devBuild and run the production server:
npm run build
npm start| Command | Description |
|---|---|
npm run dev |
Start development server with hot reload |
npm start |
Run production build |
npm run build |
Compile TypeScript to JavaScript |
npm run lint |
Check code for linting errors |
npm run lint:fix |
Fix linting errors automatically |
npm run format |
Format code with Prettier |
npm run format:check |
Check if code is formatted correctly |
npm run migrate |
Run database migrations |
# development
docker build -t backend-app:dev -f docker/development/Dockerfile .
# production
docker build -t backend-app:dev -f docker/production/Dockerfile .
# development
docker run --rm -it -v ${PWD}:/usr/src/backend-app -v /usr/src/backend-app/node_modules -p 3000:3000 backend-app:dev
# production
docker run --rm -d -v ${PWD}:/usr/src/backend-app -v /usr/src/backend-app/node_modules -p 3000:3000 backend-app:devctrl+cThis project uses ESLint for code linting:
npm run lintCode formatting is handled by Prettier:
npm run format:checkHusky ensures code quality before commits:
- Runs linting
- Runs formatting checks
- Validates commit messages
npm run migrate:create -- migration_namenpm run migratenpm run migrate:rollback- Set
NODE_ENV=production - Use strong JWT secrets
- Configure proper database credentials
- Set up proper logging
- Enable CORS for specific domains
- Set up SSL/TLS certificates
- Configure environment variables
- Run database migrations
- Test all API endpoints
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'feat: add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License.
HardCoder404
- Express.js community
- TypeScript team
- All contributors
Happy Coding! π