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 sargenjsThis 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-appThis 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 modularThis 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 --testThis 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 --testCreates a modular project with a test endpoint included.
Running Your Project
Navigate to your project
cd my-express-appInstall dependencies
npm installStart the development server
npm run devYour 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 devTest environment:
npm run testProduction 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:
ALLOWED_ORIGINS=["*"])🔧 Easy Configuration: Set ALLOWED_ORIGINS in your environment files to manage allowed domains and IPs.
What You Get
Layered Architecture
Modular Architecture
Structure Includes
Next Steps
Now that you have a basic project running, you can explore more advanced features:
sargen gen:dbsargen gen:modulesargen gen:gitsargen gen:middleware