Reference

Arkos Configuration

Arkos provides a comprehensive configuration system that allows you to customize every aspect of your application. This reference covers all available configuration options for both arkos.init() and arkos.config.ts.

The dedicated configuration file was introduced on v1.4.0-beta it was made for the clearly separate concerns between what is really application configuration and what is initialization configuration. And this also makes possible for different tools such as the Built-in CLI to make usage of the confiugration when generating different components in your project.

Key Changes From v1.4.0-beta

  • Split Configuration: Configuration is now split between arkos.init() (app initialization) and arkos.config.ts (static configuration)
  • Simplified Middleware Configuration: Individual middleware options replace complex middlewares object
  • Unified Router Registration: All custom routers use the use array
  • Enhanced ArkosRouter: New declarative configuration for routes

File Structure Changes

Configuration Structure

ArkosInitConfig (arkos.init())

Used for app initialization and runtime configuration:

interface ArkosInitConfig {
  use?: (
    | IArkosRouter
    | express.Router
    | ArkosRequestHandler
    | ArkosErrorRequestHandler
  )[];
  configureApp?: (app: express.Express) => Promise<any> | any;
  configureServer?: (server: http.Server) => Promise<any> | any;
}

ArkosConfig (arkos.config.ts)

Used for static application configuration:

interface ArkosConfig {
  // Basic settings
  welcomeMessage?: string;
  port?: number;
  host?: string;

  // Feature configurations
  authentication?: AuthenticationConfig;
  validation?: ValidationConfig;
  fileUpload?: FileUploadConfig;
  middlewares?: MiddlewareConfig;
  routers?: RouterConfig;
  email?: EmailConfig;
  swagger?: SwaggerConfig;
  request?: RequestConfig;
  debugging?: DebuggingConfig;
}

Configuration Properties

Basic Application Settings

welcomeMessage

  • Type: string
  • Default: "Welcome to our Rest API generated by Arkos, find more about Arkos at www.arkosjs.com."
  • Description: Message returned when accessing GET /api

port

  • Type: number
  • Default: 8000 or process.env.PORT or -p argument
  • Description: Port where the application will run

host

  • Type: string
  • Default: localhost
  • Description: Host to bind the server to

Authentication Configuration

authentication.enabled

  • Type: boolean
  • Default: true
  • Description: Completely disable authentication system and remove auth routes when false

authentication.mode

  • Type: "static" | "dynamic"
  • Required: Yes
  • Description: Defines whether to use Static or Dynamic Role-Based Access Control

authentication.login.allowedUsernames

  • Type: string[]
  • Default: ["username"]
  • Description: Fields that can be used as username for authentication

authentication.login.sendAccessTokenThrough

  • Type: "cookie-only" | "response-only" | "both"
  • Default: "both"
  • Description: How to return access tokens after login

authentication.rateLimit

  • Type: Partial<RateLimitOptions>
  • Default: { windowMs: 5000, limit: 10 }
  • Description: Rate limiting for authentication endpoints

authentication.jwt

  • Type: Object containing JWT configuration
  • Description: JWT token settings

Validation Configuration

validation.resolver

  • Type: "class-validator" | "zod"
  • Required: Yes
  • Description: Validation library to use

validation.strict

  • Type: boolean
  • Default: false
  • Description: Require validation configuration for all ArkosRouter endpoints

validation.validationOptions

  • Type: ValidatorOptions or Record<string, any>
  • Description: Options passed to the validation library

File Upload Configuration

fileUpload.baseUploadDir

  • Type: string
  • Default: "/uploads"
  • Description: Base directory for file uploads

fileUpload.baseRoute

  • Type: string
  • Default: "/api/uploads"
  • Description: Base route for file access

fileUpload.expressStatic

  • Type: Parameters<typeof express.static>[1]
  • Description: Options for express.static middleware

fileUpload.restrictions

  • Type: Object containing file type restrictions
  • Description: Upload restrictions for different file types

Middleware Configuration

Middleware Options

  • compression: false | CompressionOptions | ArkosRequestHandler
  • rateLimit: false | Partial<RateLimitOptions> | ArkosRequestHandler
  • cors: false | CorsConfig | ArkosRequestHandler
  • expressJson: false | express.JsonOptions | ArkosRequestHandler
  • cookieParser: false | Parameters<typeof cookieParser> | ArkosRequestHandler
  • queryParser: false | QueryParserOptions | ArkosRequestHandler
  • requestLogger: false | ArkosRequestHandler
  • errorHandler: false | express.ErrorRequestHandler

Router Configuration

routers.strict

  • Type: boolean | "no-bulk"
  • Default: false
  • Description: Strict mode for routing security (Disables all auto generated endpoints)

routers.welcomeRoute

  • Type: false | ArkosRequestHandler
  • Description: Custom welcome endpoint handler or false to disable

Advanced Configuration

use

  • Type: (IArkosRouter | express.Router | ArkosRequestHandler | ArkosErrorRequestHandler)[]
  • Description: Custom routers and middlewares to add to the application

configureApp

  • Type: (app: express.Express) => any
  • Description: Function to configure the Express app instance

configureServer

  • Type: (server: http.Server) => any
  • Description: Function to configure the HTTP server instance

Email Configuration

email.host

  • Type: string
  • Required: Yes
  • Description: SMTP host

email.port

  • Type: number
  • Default: 465
  • Description: SMTP port

email.secure

  • Type: boolean
  • Default: true
  • Description: Use secure connection

email.auth.user

  • Type: string
  • Required: Yes
  • Description: SMTP username

email.auth.pass

  • Type: string
  • Required: Yes
  • Description: SMTP password

email.name

  • Type: string
  • Description: Display name for sent emails

Swagger Configuration

swagger.enableAfterBuild

  • Type: boolean
  • Default: false
  • Description: Enable API documentation after build

swagger.endpoint

  • Type: string
  • Default: "/api/api-docs"
  • Description: Swagger UI endpoint

swagger.mode

  • Type: "prisma" | "class-validator" | "zod"
  • Required: Yes
  • Description: Schema generation mode

swagger.strict

  • Type: boolean
  • Default: false
  • Description: Strict schema validation

Request Configuration

request.parameters.allowDangerousPrismaQueryOptions

  • Type: boolean
  • Default: false
  • Description: Allow passing Prisma query options in request parameters

Debugging Configuration

Available from v1.4.0-beta

// arkos.config.ts
const arkosConfig: ArkosConfig = {
  debugging: {
    requests: {
      level: 1,
      filter: ["Query", "Body"],
    },
    dynamicLoader: {
      level: 2,
      filters: {
        modules: ["user", "product"],
        components: ["router", "service"],
      },
    },
  },
};

export default arkosConfig;

Environment Variables

Arkos.js supports the following environment variables:

VariableDescriptionDefaultRequired
PORTApplication port number8000No
NODE_ENVApplication environment mode (development, production, test)developmentNo
HOSTHost to bind the server tolocalhostNo
DATABASE_URLDatabase connection string-Yes
JWT_SECRETSecret key for JWT token signing and verification-Yes (if using authentication)
JWT_EXPIRES_INJWT token expiration time (e.g., "30d", "2h", "3600")30dNo
JWT_COOKIE_SECUREWhether JWT cookie is sent only over HTTPStrue in production, false in developmentNo
JWT_COOKIE_HTTP_ONLYWhether JWT cookie is HTTP-only (inaccessible to JavaScript)trueNo
JWT_COOKIE_SAME_SITESameSite attribute for JWT cookie (lax, strict, none)"none" in production, "lax" in developmentNo
EMAIL_HOSTSMTP server host for email service-No
EMAIL_PORTSMTP server port465No
EMAIL_SECUREUse secure SMTP connectiontrueNo
EMAIL_USERSMTP authentication username/email-No
EMAIL_PASSWORDSMTP authentication password-No
EMAIL_NAMEDisplay name for sent emails-No

Complete Example

Configuration Precedence

Configuration values are loaded in this order (highest priority first):

  1. Values passed directly to arkos.init() (v1.4) or in arkos.config.ts (v1.4)
  2. Environment variables
  3. Default values provided by Arkos.js