Express Starter Foundation
The Express Starter Foundation is the core starting block provided by servercn. It provides a robust, production‑ready Express.js setup with sensible defaults, allowing you to focus on building features rather than boilerplate.
This foundation is not a framework; it's a well-structured boilerplate that you fully own and can extend as your project grows.
Installation Guide
To install the Express Starter Foundation, run the following command:
npx servercn-cli init express-starterWhat This Foundation Solves
Most Express projects require the same initial setup:
- Environment variable configuration & validation
- CORS and security headers
- Standardized API response and error formats
- TypeScript configuration
- Development tooling (hot reload, structured logging)
The Express Starter Foundation standardizes these concerns using battle-tested patterns.
Architecture Patterns
Servercn provides two primary architectural patterns to choose from when initializing your server. You can select the one that best fits your project's scale and complexity.
1. MVC Architecture (Standard)
The MVC (Model-View-Controller) pattern is the default and is perfect for small to medium-sized applications. It separates concerns by technical role (controllers, routes, middlewares).
2. Feature Architecture (Scalable)
For larger applications, the Feature Architecture (also known as domain-driven or modular) is recommended. This structure co-locates all files related to a specific feature (e.g., user, auth) into a single module folder.
Core Features
Regardless of the architecture you choose, you get these features out of the box:
Standard Response Format
All API responses follow a predictable structure, making frontend integration seamless:
Success Response:
Error Response:
Fast-Fail Environment Validation
Environment variables are validated at startup using Zod. If a required variable (like PORT or DATABASE_URL) is missing, the server will log a clear error and exit immediately, preventing runtime crashes.
Graceful Shutdown
The foundation includes logic to handle SIGINT and SIGTERM signals, ensuring that active requests are completed and database connections are closed properly before the process exits.
Extending the Foundation
The Express Starter Foundation is cumulative. Once initialized, you can easily add:
- Database Starters: Mongoose, Drizzle (MySQL/PostgreSQL)
- Auth Components: JWT Utilities, OAuth, RBAC
- Utility Components: Logger, File Upload, Email Service
Each component you add with servercn add will automatically align with your chosen architecture.
Summary
Use the Express Starter Foundation when:
- Starting a new production-ready Express API.
- You want a clean, typed foundation without the weight of a full framework.
- You need a consistent structure that scales with your team.