Getting Started
Configuration
Learn how to configure your CanxJS application using the configuration file and environment variables.
Configuration File
Create a canx.config.ts file in your project root to customize your application settings.
canx.config.ts
1// canx.config.ts2import { defineConfig } from "canxjs";34export default defineConfig({5app: {6port: 3000,7host: "localhost",8env: "development",9debug: true,10},1112database: {13driver: "mysql",14host: process.env.DB_HOST || "localhost",15port: 3306,16database: process.env.DB_NAME || "canx_app",17username: process.env.DB_USER || "root",18password: process.env.DB_PASS || "",19},2021security: {22cors: {23enabled: true,24origin: ["http://localhost:3000"],25credentials: true,26},27rateLimit: {28enabled: true,29max: 100,30window: 60000, // 1 minute31},32},3334cache: {35driver: "memory", // or "redis"36ttl: 3600,37},38});
Environment Variables
Use environment variables to store sensitive configuration. Create a .env file in your project root.
.env
1# .env2NODE_ENV=development3PORT=300045# Database6DB_HOST=localhost7DB_PORT=33068DB_NAME=canx_app9DB_USER=root10DB_PASS=secret1112# Security13JWT_SECRET=your-secret-key14SESSION_SECRET=your-session-secret1516# Cache17REDIS_URL=redis://localhost:6379
Configuration Options
App Configuration
Core application settings
| Option | Type | Default | Description |
|---|---|---|---|
| port | number | 3000 | Server port |
| host | string | localhost | Server hostname |
| env | string | development | Environment mode |
| debug | boolean | false | Enable debug mode |
Database Configuration
Database connection settings
| Option | Type | Default | Description |
|---|---|---|---|
| driver | string | mysql | Database driver (mysql, postgres) |
| host | string | localhost | Database host |
| port | number | 3306 | Database port |
| database | string | - | Database name |
| username | string | - | Database username |
| password | string | - | Database password |
Security Configuration
Security and authentication settings
| Option | Type | Default | Description |
|---|---|---|---|
| cors.enabled | boolean | true | Enable CORS |
| cors.origin | string | array | * | Allowed origins |
| rateLimit.enabled | boolean | true | Enable rate limiting |
| rateLimit.max | number | 100 | Max requests per window |
| rateLimit.window | number | 60000 | Window in ms |