A robust and scalable Express.js boilerplate with modern development practices and essential middleware setup.
- Express.js 5.x - Latest version of Express framework
- MongoDB Integration - Database connectivity with Mongoose
- Environment Configuration - Flexible configuration management
- Global Error Handling - Centralized error handling middleware
- ES6 Modules - Modern JavaScript module system
- Development Tools - ESLint for code quality and Husky for Git hooks
- Docker Support - Containerized development environment
- GitHub Actions - Automated CI/CD pipeline for testing and linting
- Utility Functions - Helper functions for common operations
express-boilerplate/
├── src/
│ ├── config/
│ │ ├── config.js # Application configuration
│ │ └── mongoose.js # MongoDB connection setup
│ └── utilis/
│ ├── returnResponse.js # Response formatting utility
│ └── validateMissingFields.js # Field validation utility
├── app.js # Express application setup
├── server.js # Server startup file
├── Dockerfile # Docker configuration for development
├── .github/workflows/ # GitHub Actions CI/CD workflows
├── .env.sample # Environment variables template
├── .gitignore # Git ignore rules
├── eslint.config.js # ESLint configuration
└── package.json # Project dependencies and scripts
- Node.js (v18 or higher, recommended: v20 or v22)
- MongoDB (local or cloud instance)
- npm or yarn
- Clone the repository:
git clone <repository-url>
cd express-boilerplate- Install dependencies:
npm install- Set up environment variables:
cp .env.sample .env- Configure your
.envfile:
NODE_ENVIRONMENT=development
PORT=3000
dbURI=mongodb://localhost:27017/your-database-namenpm run devThis will start the server with nodemon for automatic restarting on file changes.
npm startnpm run dev- Start development server with nodemonnpm run lint- Run ESLint to check code qualitynpm test- Run tests (currently placeholder)npm run prepare- Set up Husky git hooks
Note: The included Dockerfile is optimized for development purposes and is not production-ready.
Build and run the application using Docker for development:
# Build the Docker image
docker build -t express-boilerplate .
# Run the container
docker run -p 3000:3000 --env-file .env express-boilerplateFor production deployment, you should create a separate production-optimized Dockerfile with multi-stage builds, security hardening, and optimized layer caching.
This project uses GitHub Actions for automated testing and code quality checks.
The CI pipeline runs on every push to the main branch and includes:
- Multi-Node Testing - Tests against Node.js versions 18.x, 20.x, and 22.x
- Dependency Installation - Uses
npm cifor clean, reproducible builds - Code Linting - Runs ESLint to ensure code quality standards
The workflow is defined in .github/workflows/backendCI.yaml and automatically:
- Checks out the code
- Sets up the Node.js environment
- Installs dependencies
- Runs linting checks
This ensures that all code pushed to the main branch meets quality standards and is compatible across supported Node.js versions.
| Variable | Description | Default |
|---|---|---|
NODE_ENVIRONMENT |
Application environment (development/production) | development |
PORT |
Server port | 3000 |
dbURI |
MongoDB connection string | - |
The boilerplate includes:
- Global Error Handler - Centralized error handling with stack traces in development
- JSON & URL-encoded Body Parsing - Built-in middleware for request parsing
- Utility Functions - Common helper functions for response formatting and validation
This project uses ESLint for maintaining code quality. Run the linter before committing:
npm run lintHusky is configured to run pre-commit hooks. The hooks are automatically installed when you run npm install.
- Create feature branches from
main - Follow the existing project structure
- Add appropriate error handling
- Update documentation as needed
- Ensure code passes linting
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Ensure all checks pass
- Submit a pull request
This project is licensed under the ISC License.
For questions or issues, please create an issue in the repository.