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.

Expressjs Official Docs

Installation Guide

To install the Express Starter Foundation, run the following command:

npx servercn-cli init express-starter

What 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.

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).

src/
├── configs/
├── constants/
├── controllers/
├── middlewares/
├── routes/
├── utils/
├── app.ts
└── server.ts

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.

src/
├── configs/
├── modules/
│   ├── auth/
│   ├── users/
│   └── health/
├── routes/
├── shared/
│   ├── constants/
│   ├── errors/
│   ├── middlewares/
│   └── utils/
├── app.ts
└── server.ts

Core Features

Regardless of the architecture you choose, you get these features out of the box:

All API responses follow a predictable structure, making frontend integration seamless:

Success Response:

{
  "success": true,
  "message": "Request successful",
  "statusCode": 200,
  "data": { ... }
}

Error Response:

{
  "success": false,
  "message": "Invalid request",
  "statusCode": 400,
  "errors": []
}

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.

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.

File & Folder Structure

ServerCN

Select a file to view its contents

Installation

npx servercn-cli init express-starter