A clean, modern Node.js/TypeScript project template with Express, Docker, and best practices.
- ⚡ TypeScript - Full type safety and modern JavaScript features
- 🚀 Express.js - Fast, unopinionated web framework
- 🐳 Docker - Containerized development and production
- 🧪 Jest - Comprehensive testing framework
- 📝 ESLint + Prettier - Code quality and formatting
- 🔒 Security - Helmet.js for security headers
- 📊 Health Checks - Built-in monitoring endpoints
- 🏗️ Modular Structure - Clean, scalable architecture
- Node.js 18+
- Docker and Docker Compose
- Yarn or npm
-
Clone or copy the project:
# If you're starting from this template git clone <your-repo-url> cd new-project-base
-
Install dependencies:
yarn install # or npm install -
Set up environment:
cp env.example .env # Edit .env with your configuration -
Start development server:
# Using Docker (recommended) yarn dev # Or locally yarn start:dev
The server will be available at http://localhost:3000
| Script | Description |
|---|---|
yarn dev |
Start development with Docker |
yarn start:dev |
Start development server locally |
yarn build |
Build for production |
yarn start |
Start production server |
yarn test |
Run tests |
yarn test:watch |
Run tests in watch mode |
yarn lint |
Run ESLint |
yarn lint-fix |
Fix ESLint issues |
yarn prettier |
Format code with Prettier |
src/
├── controllers/ # Request handlers (uses usecases)
├── entities/ # Domain entities
├── interfaces/ # Repository and usecase interfaces
├── middleware/ # Express middleware
├── repositories/ # Data access layer
├── routes/ # API routes
├── services/ # Business logic services
├── types/ # TypeScript type definitions
├── usecases/ # Application usecases (clean architecture)
├── utils/ # Utility functions
├── tests/ # Test files
└── index.ts # Application entry point
GET /health- Application health status
GET /users- List users with pagination and filtersPOST /users- Create a new userGET /users/:id- Get a specific userPUT /users/:id- Update a userDELETE /users/:id- Delete a user
GET /example- Example endpointGET /example/:id- Example with parameterPOST /example- Example POST endpoint
The project follows Clean Architecture principles with the following layers:
- Entities (
src/entities/) - Domain models - Use Cases (
src/usecases/) - Application business logic - Controllers (
src/controllers/) - Request/response handling - Routes (
src/routes/) - API endpoints - Repositories (
src/repositories/) - Data access layer - Services (
src/services/) - Business logic services
- Create Entity (
src/entities/user.entity.ts) - Create Repository (
src/repositories/user.repository.ts) - Create Use Cases (
src/usecases/user/) - Create Controller (
src/controllers/user.controller.ts) - Create Routes (
src/routes/users.ts) - Add to main app (
src/index.ts)
// src/routes/users.ts
import { Router } from "express";
import { UserController } from "../controllers/user.controller";
const router = Router();
const userController = new UserController();
router.get("/", userController.listUsers.bind(userController));
router.post("/", userController.createUser.bind(userController));
router.get("/:id", userController.getUser.bind(userController));
export const usersRouter = router;- Create middleware in
src/middleware/ - Import and use in
src/index.ts
Copy env.example to .env and configure:
NODE_ENV- Environment (development/production)PORT- Server port (default: 3000)LOG_LEVEL- Logging level (default: info)
# Run all tests
yarn test
# Run tests in watch mode
yarn test:watch
# Run tests with coverage
yarn test --coverageyarn devdocker build -t my-app .
docker run -p 3000:3000 my-app# Start all services
docker-compose up
# Start in background
docker-compose up -d
# Stop services
docker-compose downyarn build
yarn startdocker build --target production -t my-app .
docker run -p 3000:3000 my-appThis project is ready for Railway deployment!
# Connect your GitHub repository to Railway
# Railway will automatically deploy on push
# Or use Railway CLI:
npm install -g @railway/cli
railway login
railway link
railway up- Connect Repository: Go to Railway Dashboard
- Create Project: Click "New Project" → "Deploy from GitHub repo"
- Select Repository: Choose your repository
- Deploy: Railway will automatically deploy on push
Railway automatically provides necessary environment variables:
PORT- Automatically assigned by RailwayNODE_ENV- Set to "production" in production environments
# In Railway Dashboard:
# 1. Go to "New" → "Database" → "PostgreSQL"
# 2. Railway will provide DATABASE_URL automatically📖 Detailed Railway Guide: See RAILWAY_DEPLOYMENT.md for comprehensive deployment instructions.
- Follow the existing code style
- Add tests for new features
- Update documentation as needed
- Run linting before committing
MIT License - see LICENSE file for details