Getting Started

Get up and running with SargenJS in minutes. This guide will walk you through creating your first Express.js project.

Prerequisites

Before you begin, make sure you have the following installed and basic knowledge of these tools:

Required Installation

  • Node.js 14 or higher
  • npm (comes with Node.js)
  • Git (optional, for version control)

Knowledge Prerequisites

  • Sequelize & Sequelize CLI
  • Redis & Docker
  • GitHub & GitHub CLI
  • Grafana, Loki & Prometheus

Installation

Install SargenJS globally using npm:

npm install -g sargenjs

This will make the sargen command available globally on your system.

Creating a New Project

Basic Project (Layered Architecture)

Create a new project with the default layered (MVC) architecture:

sargen init my-express-app

This creates a new directory called my-express-app with a complete Express.js project structure.

Modular Architecture

Create a project with modular (feature-based) architecture:

sargen init my-express-app --struct modular

This creates a project organized by features/modules rather than layers.

Generate with Test Endpoint

Generate new project with a test endpoint for quick validation:

sargen init my-express-app --test

This adds a test endpoint at http://localhost:8000/api/v1/test/test-api

Combined Options

You can combine multiple options:

sargen init my-express-app --struct modular --test

Creates a modular project with a test endpoint included.

Running Your Project

Navigate to your project

cd my-express-app

Install dependencies

npm install

Start the development server

npm run dev

Your Express.js application will be running at http://localhost:8000

Environment Management

Multiple Environment Support

SargenJS automatically creates multiple environment files for different deployment scenarios:

  • .env - Development environment
  • .env.test - Test environment
  • .env.production - Production environment

Available Scripts

Development mode (default):

npm run dev

Test environment:

npm run test

Production environment:

npm run prod

💡 Cross-Platform Support: All scripts use cross-env for seamless environment variable handling across Windows, macOS, and Linux.

CORS Management

SargenJS includes dynamic CORS configuration for managing allowed origins:

Development:Allows all origins (ALLOWED_ORIGINS=["*"])
Test:Allows localhost origins for testing
Production:Requires explicit domain configuration

🔧 Easy Configuration: Set ALLOWED_ORIGINS in your environment files to manage allowed domains and IPs.

What You Get

Layered Architecture

my-express-app/
├── src/
│ ├── routes/
│ │ └── index.js
│ ├── controllers/
│ └── services/
├── app.js
├── .env
├── .env.test
├── .env.production
├── .gitignore
└── package.json

Modular Architecture

my-express-app/
├── src/
│ ├── config/
│ ├── common/
│ └── modules/
├── app.js
├── .env
├── .env.test
├── .env.production
├── .gitignore
└── package.json

Structure Includes

Express.js setup with essential middleware
Security headers with Helmet
CORS configuration
Express Body parser for JSON and URL-encoded data
Structured API routing with versioning
Environment configuration (.env, .env.test, .env.production)
Git ignore file for Node.js projects
README.md with project information

Next Steps

Now that you have a basic project running, you can explore more advanced features:

Set up database configuration with sargen gen:db
Generate modules and CRUD APIs with sargen gen:module
Initialize Git repository with sargen gen:git
Add middleware with sargen gen:middleware