Installation

This guide will help you install and set up Servercn in your Node.js project.

Prerequisites

Before installing Servercn, ensure you have:

  • Node.js version 18 or higher
  • npm, yarn, bun or pnpm package manager
  • An existing Node.js project (or create a new with servercn foundations)

Quick Start

The fastest way to get started with Servercn:

npx servercn-cli init

After running the command, you will be prompted to choose a project foundation:

  Select a project foundation:  » - Use arrow-keys. Return to submit.
> Express Starter - Minimal Express server setup
  Express + Mongoose
  Express + MySQL (Drizzle)
  Express + PostgreSQL (Drizzle)
  Existing Project

Choose the foundation that best fits your project requirements and press Enter to continue.

npx servercn-cli add error-handler

Servercn Foundations (Recommended)

You can directly start your project with servercn foundations. Initializing with foundations will set up the project with the foundation's configuration and dependencies.

The Express Starter Foundation is the core starting block provided by servercn.

npx servercn-cli init express-starter

Express Starter Docs

The Drizzle MySQL Starter is a database foundation provided by servercn for projects that use MySQL with Drizzle ORM.

npx servercn-cli init drizzle-mysql-starter

Drizzle MySQL Starter Docs

The Drizzle PostgreSQL Starter is a database foundation provided by servercn for projects that use PostgreSQL with Drizzle ORM.

npx servercn-cli init drizzle-pg-starter

Drizzle PostgreSQL Starter Docs

The Mongoose Starter is a database foundation provided by servercn for projects that use MongoDB with Mongoose ODM.

npx servercn-cli init mongoose-starter

Mongoose Starter Docs

Configuration Options

Project Root Directory

  • Default: . (current directory)
  • The root directory where your project lives

Source Directory

  • Default: src
  • Where your source code will be located

Architecture

  • MVC: Traditional Model-View-Controller structure
  • Feature-based: Feature-module architecture

Language

  • TypeScript: for type safety

Backend Framework

  • Express: Currently supported framework

Database

  • MongoDB: With Mongoose ODM
  • MySQL: With Drizzle ORM
  • PostgreSQL: With Drizzle ORM
  • More databases coming soon

servercn.config.json

This file stores your project configuration and is used by Servercn to generate components in the correct structure.

{
  "$schema": "https://servercn.vercel.app/schema/servercn.config.json",
  "version": "1.1.4",
  "project": {
    "root": ".",
    "type": "backend",
    "packageManager": "npm"
  },
  "stack": {
    "runtime": "node",
    "language": "typescript",
    "framework": "express",
    "architecture": "mvc"
  },
  "database": {
    "engine": "mongodb",
    "adapter": "mongoose"
  },
  "meta": {
    "createdAt": "2026-02-26T11:15:30.945Z",
    "createdBy": "servercn@1.1.4"
  }
}

Databases

Servercn provides first-class support for popular databases through well-integrated ORMs and ODMs. This ensures your project follows best practices for data modeling and type safety.

  • MongoDB with Mongoose

  • MySQL with Drizzle

  • PostgreSQL with Drizzle

Adding Components

Once initialized, you can add components to your project:

# Add a component
npx servercn-cli add <component-name>
 
# Examples
npx servercn-cli add error-handler
 
# Add multiple components
npx servercn-cli add jwt-utils http-status-codes

Updating Configuration

You can manually edit servercn.config.json to change your project configuration:

{
  "stack": {
    "architecture": "feature" // Change from "mvc" to "feature"
  }
}

After updating, new components will use the updated configuration.

Next Steps

After installation:

  1. Add your first component: npx servercn-cli add error-handler
  2. Set up your Express app: Create src/app.ts
  3. Add more components: Explore available components with npx servercn-cli list
  4. Read component docs: Each component has detailed documentation

Getting Help

Note: Servercn doesn't install itself as a runtime dependency. Components are copied into your codebase, so you own the code completely.