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.ts
2import { defineConfig } from "canxjs";
3
4export default defineConfig({
5 app: {
6 port: 3000,
7 host: "localhost",
8 env: "development",
9 debug: true,
10 },
11
12 database: {
13 driver: "mysql",
14 host: process.env.DB_HOST || "localhost",
15 port: 3306,
16 database: process.env.DB_NAME || "canx_app",
17 username: process.env.DB_USER || "root",
18 password: process.env.DB_PASS || "",
19 },
20
21 security: {
22 cors: {
23 enabled: true,
24 origin: ["http://localhost:3000"],
25 credentials: true,
26 },
27 rateLimit: {
28 enabled: true,
29 max: 100,
30 window: 60000, // 1 minute
31 },
32 },
33
34 cache: {
35 driver: "memory", // or "redis"
36 ttl: 3600,
37 },
38});

Environment Variables

Use environment variables to store sensitive configuration. Create a .env file in your project root.

.env
1# .env
2NODE_ENV=development
3PORT=3000
4
5# Database
6DB_HOST=localhost
7DB_PORT=3306
8DB_NAME=canx_app
9DB_USER=root
10DB_PASS=secret
11
12# Security
13JWT_SECRET=your-secret-key
14SESSION_SECRET=your-session-secret
15
16# Cache
17REDIS_URL=redis://localhost:6379

Configuration Options

App Configuration

Core application settings

OptionTypeDefaultDescription
portnumber3000Server port
hoststringlocalhostServer hostname
envstringdevelopmentEnvironment mode
debugbooleanfalseEnable debug mode

Database Configuration

Database connection settings

OptionTypeDefaultDescription
driverstringmysqlDatabase driver (mysql, postgres)
hoststringlocalhostDatabase host
portnumber3306Database port
databasestring-Database name
usernamestring-Database username
passwordstring-Database password

Security Configuration

Security and authentication settings

OptionTypeDefaultDescription
cors.enabledbooleantrueEnable CORS
cors.originstring | array*Allowed origins
rateLimit.enabledbooleantrueEnable rate limiting
rateLimit.maxnumber100Max requests per window
rateLimit.windownumber60000Window in ms

Next Steps

Now that you understand configuration, learn about routing and controllers.