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:
1. Initialize Servercn in your project
npx servercn-cli initAfter running the command, you will be prompted to choose a project foundation:
Choose the foundation that best fits your project requirements and press Enter to continue.
2. Add your first component
npx servercn-cli add error-handlerServercn 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.
1. Express Starter
The Express Starter Foundation is the core starting block provided by servercn.
npx servercn-cli init express-starter2. Drizzle MySQL Starter
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-starter3. Drizzle PostgreSQL Starter
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-starterDrizzle PostgreSQL Starter Docs
4. Mongoose Starter
The Mongoose Starter is a database foundation provided by servercn for projects that use MongoDB with Mongoose ODM.
npx servercn-cli init mongoose-starterConfiguration 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.
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:
Updating Configuration
You can manually edit servercn.config.json to change your project configuration:
After updating, new components will use the updated configuration.
Next Steps
After installation:
- Add your first component:
npx servercn-cli add error-handler - Set up your Express app: Create
src/app.ts - Add more components: Explore available components with
npx servercn-cli list - Read component docs: Each component has detailed documentation
Getting Help
- Documentation: Check component-specific docs in
/docs/** - Issues: Report issues on GitHub
- Community: Join our community discussions
- Discord: Join our Discord community.
Note: Servercn doesn't install itself as a runtime dependency. Components are copied into your codebase, so you own the code completely.