Welcome to the Express TypeScript Boilerplate 2024 – a streamlined, efficient, and scalable foundation for building powerful backend services. This boilerplate merges modern tools and practices in Express.js and TypeScript, enhancing productivity, code quality, and performance.
Developed to streamline backend development, this boilerplate is your solution for:
- ✨ Reducing setup time for new projects.
- 📊 Ensuring code consistency and quality.
- ⚡ Facilitating rapid development with cutting-edge tools.
- 🛡️ Encouraging best practices in security, testing, and performance.
- 📁 Modular Structure: Organized by feature for easy navigation and scalability.
- 💨 Faster Execution with tsx: Rapid TypeScript execution with esbuild, complemented by tsc for type checking.
- 🌐 Stable Node Environment: Latest LTS Node version in .nvmrc.
- 🔧 Simplified Environment Variables with Envalid: Centralized and easy-to-manage configuration.
- 🔗 Path Aliases: Cleaner code with shortcut imports.
- 🔄 Dependabot Integration: Automatic updates for secure and up-to-date dependencies.
- 🔒 Security: Helmet for HTTP header security and CORS setup.
- 📊 Logging: Efficient logging with pino-http.
- 🧪 Comprehensive Testing: Robust setup with Vitest and Supertest.
- 🔑 Code Quality Assurance: Husky and lint-staged for consistent quality.
- ✅ Unified Code Style: ESLint and Prettier for a consistent coding standard.
- 📃 API Response Standardization: ServiceResponse class for consistent API responses.
- 🐳 Docker Support: Ready for containerization and deployment.
- 📝 Input Validation with Zod: Strongly typed request validation using Zod.
- 🧩 API Spec Generation: Automated OpenAPI specification generation from Zod schemas to ensure up-to-date and accurate API documentation.
- Clone the repository:
git clone https://github.com/edwinhern/express-typescript-2024.git
- Navigate:
cd express-typescript-2024
- Install dependencies:
npm ci
- Create
.env
: Copy.env.template
to.env
- Update
.env
: Fill in necessary environment variables
- Development Mode:
npm run dev
- Building:
npm run build
- Production Mode: Set
.env
toNODE_ENV="production"
thennpm run build && npm run start
.
├── api
│ ├── healthCheck
│ │ ├── __tests__
│ │ │ └── healthCheckRouter.test.ts
│ │ └── healthCheckRouter.ts
│ └── user
│ ├── __tests__
│ │ ├── userRouter.test.ts
│ │ └── userService.test.ts
│ ├── userModel.ts
│ ├── userRepository.ts
│ ├── userRouter.ts
│ └── userService.ts
├── api-docs
│ ├── __tests__
│ │ └── openAPIRouter.test.ts
│ ├── openAPIDocumentGenerator.ts
│ ├── openAPIResponseBuilders.ts
│ └── openAPIRouter.ts
├── common
│ ├── __tests__
│ │ ├── errorHandler.test.ts
│ │ └── requestLogger.test.ts
│ ├── middleware
│ │ ├── errorHandler.ts
│ │ ├── rateLimiter.ts
│ │ └── requestLogger.ts
│ ├── models
│ │ └── serviceResponse.ts
│ └── utils
│ ├── commonValidation.ts
│ ├── envConfig.ts
│ └── httpHandlers.ts
├── index.ts
└── server.ts
Objective: This SOP outlines the steps to install and set up the intracom-be-06-2024
application.
- SSH access
- Git installed
- Node.js and npm installed
- Docker Desktop installed
- MongoDB community server image available on Docker Hub
-
Setup SSH Key:
- Generate an SSH key if you don't have one:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
- Add the SSH key to your SSH agent:
eval "$(ssh-agent -s)"
andssh-add ~/.ssh/id_rsa
- Add the SSH key to your GitHub account.
- Generate an SSH key if you don't have one:
-
Clone the Repository:
- Clone the
intracom-be-06-2024
repository:git clone https://github.com/project-ascend-io/intracom-be-06-2024 cd intracom-be-06-2024
- Clone the
-
Install Dependencies:
- Navigate to the project directory and run:
npm install
- Navigate to the project directory and run:
-
Setup Environment Variables:
-
Create a
.env
file in the root directory of your project with the following content that matches the .env.template:NODE_ENV=development PORT=8080 HOST=localhost # CORS Settings CORS_ORIGIN=http://localhost:* # Rate Limiting COMMON_RATE_LIMIT_WINDOW_MS=1000 COMMON_RATE_LIMIT_MAX_REQUESTS=20 # MongoDB Settings MONGO_INITDB_DATABASE=intracom_database MONGO_INITDB_ROOT_USERNAME=root MONGO_INITDB_ROOT_PASSWORD=root MONGODB_USER=<username> MONGODB_PASSWORD=<password> MONGODB_CONNECTION_STRING=mongodb://root:root@localhost:27017/
-
-
Install and Run Docker Desktop:
- Download and install Docker Desktop from Docker's official website.
- Make sure your Docker Desktop is running.
-
Run Docker Compose:
-
Change directories to the database directory:
cd database
-
Run the docker-compose command:
docker-compose up -d --build
-
-
Setup MongoDB Replica Set:
- Check to make sure your Docker containers are running:
docker ps
- Connect to mongo1 container:
docker exec -it mongo1 mongosh -u root -p root
- Run replica set initiation command:
rs.initiate({_id:'rs0',members:[{_id:0,host:'host.docker.internal:27017',priority:1},{_id:1,host:'host.docker.internal:27018',priority:0.5},{_id:2,host:'host.docker.internal:27019',priority:0.5}]})
- Verify Replica Set Configuration:
rs.status()
- You should see an output with information from the initiate command you used to set up the replica set.
- Check to make sure your Docker containers are running:
-
Run the Application:
- Start the application with:
npm run dev
- Start the application with:
-
Access the Application:
- Open your browser and navigate to
http://localhost:8080
to see the running application.
- Open your browser and navigate to
For further details or troubleshooting, please refer to the respective documentation of each tool used.