---
title: Configuration
project: Total.js V4
version: 0.0.99
section: reference
language: en
license: MIT
url: https://totaljs.es/docs/total-js-v4/0-0-99/reference/configuration/
updated: 2026-11-16T15:41:00.817Z
---

# Configuration

> The CONF object, every built-in config key and the functions for loading configuration.

The configuration lives in the files `config`, `config-debug` and `config-release` in the root of the application, and in the global object `CONF`. The guide [Configuration](../../guides/configuration/) explains the syntax, the types and environment variables; this page lists the functions and the built-in keys with their defaults.

## API

### CONF

Type: `property`

The global object with the whole configuration of the application.

Returns: `Object`

Total.js fills `CONF` with default values, then with `options.config` from the start script, and then with the values from `config` and `config-debug` or `config-release`. It is a plain object: read and assign keys as properties. Keys with a dot, like `security.txt`, need the bracket notation.

Your own keys are stored the same way as the built-in ones. Values assigned in code are not saved to the files.

Example: Read values
```js
exports.install = function() {
	ROUTE('GET /api/info/', info);
};

function info() {
	this.json({ name: CONF.name, version: CONF.version });
}
```

Example: In a view
```html
<footer>@{CONF.name} v@{CONF.version}</footer>
```

### LOADCONFIG(value)

Type: `method`

Merges new values into `CONF` at runtime.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `Object|String|Array` | yes |  | The new values. |

`value` can be:

- an object, copied key by key into `CONF`;
- a string in the config syntax, parsed with `String.parseConfig()`;
- an array of items `{ id, type, value }` (`key` or `name` instead of `id`, `body` instead of `value`).

For arrays, `type` converts the value: `number`, `boolean` (`bool`), `json` (`object`), `date`, `string`, `[string]`, `[number]`, `[boolean]` (`[bool]`). A string value that starts with `hex ` is decoded from hex.

A `root` key is copied to `default_root`, and `default_root` gets a leading and a trailing slash. Changing `mail_smtp` or `mail_smtp_options` clears the cached SMTP settings, and the TMS endpoint is refreshed.

Example: Settings from a database
```js
// Items stored e.g. in a database: [{ id, type, value }]
function applysettings(items) {
	LOADCONFIG(items);
}
```

Example: An object or a string
```js
LOADCONFIG({ allow_tms: true, secret_tms: 'token' });
LOADCONFIG('name : My Shop\nlimit (number) : 50');
```

Example: Typed items
```js
LOADCONFIG([
	{ id: 'limit', type: 'number', value: '50' },
	{ id: 'languages', type: '[string]', value: 'en, sk' },
	{ id: 'newsletter', type: 'boolean', value: 'on' }
]);
```

### DEBUG

Type: `property`

`true` when the application runs in debug mode.

Returns: `Boolean`

In debug mode Total.js reads `config-debug` and `.env-debug`; otherwise `config-release` and `.env-release`.

Example: Mode-specific code
```js
if (DEBUG)
	console.log('Running with config-debug');
```

### RELEASE

Type: `property`

`true` when the application runs in release mode.

Returns: `Boolean`

The opposite of `DEBUG`. In release mode Total.js reads `config-release` and `.env-release`, and `default_response_maxage` is used for the `Cache-Control` header of static files.

Example: Release only
```js
if (RELEASE)
	CONF.allow_tms = true;
```

### String.parseConfig([def], [onerr])

Type: `method`

Parses text in the config syntax into an object.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `def` | `Object` | no |  | Default values, copied into the result first. |
| `onerr` | `Function` | no |  | `function(err, line)` called when an `object` value cannot be evaluated. Without it, an error is thrown. |

Returns: `Object` The parsed values.

Each `key : value` line becomes a property. The value starts two characters after the `:`, so keep a space after it. Lines starting with `#` or `//` are skipped. Types in brackets work as in the config file: `string`, `number` (`float`, `double`, `currency`), `boolean` (`bool`), `array`, `json`, `object` (`eval`), `env` (`environment`), `date` (`time`, `datetime`), `random`, and `config`, which copies the value of another `CONF` key. Without a type the value stays a string.

Example: Parse settings
```js
var obj = 'name : Shop\nlimit (number) : 10\nhost (config) : url'.parseConfig();
// obj.limit === 10, obj.host === CONF.url
```

### String.parseENV()

Type: `method`

Parses text in the `.env` syntax into an object.

Returns: `Object` The parsed variables, all strings.

Each `KEY=value` line becomes a property. Quotes around the value are removed, other values are trimmed, and `\n` becomes a new line. Lines starting with `#` or `//` are skipped. Total.js uses it for the `.env` files.

Example: Parse variables
```js
var env = 'PORT=8000\nNAME="My app"'.parseENV();
// { PORT: '8000', NAME: 'My app' }
```

### KEY=value

Type: `config`

Files with environment variables, loaded before the config files.

Total.js reads `.env` from the root, then `.env-debug` or `.env-release`. Every variable goes into `process.env`, but a variable that already exists there is not replaced. Use the `(env)` type in the config to read a variable into a key.

Example: .env
```text
DATABASE_URL=postgresql://user:pass@localhost:5432/shop
PORT=8000
```

Example: config
```text
database (env) : DATABASE_URL
default_port   : auto
```

### PATH.configs([filename])

Type: `method`

Returns the path to a file in the `configs` directory.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `filename` | `String` | no |  | A file name inside the directory. |

Returns: `String` The absolute path.

The directory is set by `directory_configs` (default `/configs/`). Total.js does not load files from it; it is a place for your own configuration files.

Example: Read a JSON file
```js
var menu = require('fs').readFileSync(PATH.configs('menu.json')).toString('utf8').parseJSON();
```

### name : Total.js

Type: `config`

The name of the application.

Returns: `String`

Used in the process title, the console header, the sender name of emails, page titles and the `x-app` header of Total API calls.

Default: `Total.js`.

Example: In the config file
```text
name : My Shop
```

### version : 1.0.0

Type: `config`

The version of the application.

Returns: `String`

Always kept as a string. Without `etag_version`, the version without dots and spaces is used as the ETag suffix of static files; change `etag_version` to make browsers download static files again. `author` holds the author, shown in the console header and used as the default author meta tag.

Default: `1.0.0`.

Example: In the config file
```text
version : 2.1.0
```

### url : <value>

Type: `config`

The public URL of the application.

Returns: `String`

Used by the Total API logger as the application name and as the base URL for JSON schema references. Not set by default.

Example: In the config file
```text
url : https://www.example.com
```

### secret : <value>

Type: `config`

The key used by `ENCRYPT()` and `DECRYPT()`.

Returns: `String`

The default value is a hash of the framework path, the machine and the Node.js versions, so it changes when you move the application. Set your own value when encrypted data must survive a move. Always kept as a string.

Example: In the config file
```text
secret : my-long-random-secret
```

### secret_uid : <value>

Type: `config`

A value that makes the generated `UID()` values unique for the application.

Returns: `String`

Without a value Total.js computes it from `name`.

Example: In the config file
```text
secret_uid : shop
```

### secret_encryption : null

Type: `config`

Enables encryption of request and response bodies.

Returns: `String`

When set, the bodies of routes with the `encrypt` flag (and of WebSockets with encryption) are encrypted with this key. With `allow_static_encryption`, static files are encrypted too.

Default: `null`.

Example: In the config file
```text
secret_encryption : my-encryption-key
```

### secret_csrf : null

Type: `config`

Enables CSRF tokens.

Returns: `String`

The key used to create and check CSRF tokens. Routes with the `csrf` flag are checked only when this key is set. `default_csrf_maxage` (default `30 minutes`) sets how long a token is valid.

Default: `null`.

Example: In the config file
```text
secret_csrf : my-csrf-key
default_csrf_maxage : 30 minutes
```

### default_root : <value>

Type: `config`

The URL prefix when the application runs in a subdirectory.

Returns: `String`

Total.js adds a leading and a trailing slash. The prefix is used for URLs of static files and in redirects, and removed from incoming URLs. `root` is an alias: when set, it is copied to `default_root`. Load it from an environment variable with `default_root (env) : APP_ROOT`.

Example: In the config file
```text
default_root : /shop/
```

### default_port : <value>

Type: `config`

The HTTP port.

Returns: `Number|String`

Used when the start script does not set a port. `auto` takes `process.env.PORT`. Without any value the port is `8000`.

`default_ip` sets the IP address (without a value, or with `auto`, the server listens on `0.0.0.0`) and `default_unixsocket` a Unix socket path. Both are used only when the start script does not set them.

Example: In the config file
```text
default_port : auto
default_ip   : 127.0.0.1
```

### default_timezone : utc

Type: `config`

The time zone of the process.

Returns: `String`

Assigned to `process.env.TZ` when the config is loaded.

Default: `utc`.

Example: In the config file
```text
default_timezone : Europe/Berlin
```

### default_theme : <value>

Type: `config`

The default theme.

Returns: `String`

The name of a folder in `themes/` used by views and static files when no theme is set.

Example: In the config file
```text
default_theme : default
```

### default_request_maxlength : 10

Type: `config`

The maximum size of a request body, in kilobytes.

Returns: `Number`

Applies to routes without their own length. Parsed as an integer.

Default: `10`.

Example: In the config file
```text
default_request_maxlength : 1024
```

### default_request_timeout : 3000

Type: `config`

The request timeout, in milliseconds.

Returns: `Number`

Applies to routes without their own timeout. Parsed as an integer.

Default: `3000`.

Example: In the config file
```text
default_request_timeout : 10000
```

### default_request_maxkeys : 33

Type: `config`

The maximum number of keys parsed from a query string or a URL-encoded body.

Returns: `Number`

Extra keys are ignored. `default_request_maxkey` (default `25`) is the maximum length of one key.

Default: `33`.

Example: In the config file
```text
default_request_maxkeys : 50
```

### default_restbuilder_timeout : 10000

Type: `config`

The default timeout of `RESTBuilder` and `REQUEST()`, in milliseconds.

Returns: `Number`

Used when the request has no timeout of its own. `default_proxy` sets a proxy server (for example `http://proxy.example.com:3128`) for outgoing requests that do not set their own.

Default: `10000`.

Example: In the config file
```text
default_restbuilder_timeout : 30000
```

### default_websocket_maxlength : 2

Type: `config`

The maximum size of a WebSocket message, in kilobytes.

Returns: `Number`

Applies to WebSocket routes without their own length.

Default: `2`.

Example: In the config file
```text
default_websocket_maxlength : 64
```

### default_websocket_maxlatency : 2000

Type: `config`

The maximum latency of a WebSocket client, in milliseconds.

Returns: `Number`

Total.js pings clients every `default_interval_websocket_ping` milliseconds and closes clients with a higher latency. `0` disables the pinging.

Default: `2000`.

Example: In the config file
```text
default_websocket_maxlatency : 5000
```

### default_cors : null

Type: `config`

Allowed origins for cross-origin requests.

Returns: `Array`

Hostnames separated by commas or spaces, without the protocol (a leading `//` is removed). Requests from other origins get `null` as the allowed origin. The value is stored as a lowercase array.

`default_cors_maxage` (default `120`) sets how long browsers can cache a preflight response, in seconds.

Default: `null`.

Example: In the config file
```text
default_cors : example.com, app.example.com
```

### default_response_maxage : 11111111

Type: `config`

The `max-age` of the `Cache-Control` header for static files, in seconds.

Returns: `String`

Used only in release mode.

Default: `11111111`.

Example: In the config file
```text
default_response_maxage : 86400
```

### default_cookies_samesite : Lax

Type: `config`

The default `SameSite` attribute of cookies.

Returns: `String`

Used when a cookie does not set `samesite`. `default_cookies_secure` (default `false`) adds the `Secure` attribute to cookies that do not set `secure`.

Default: `Lax`.

Example: In the config file
```text
default_cookies_samesite : Strict
default_cookies_secure   : true
```

### default_errorbuilder_errors : false

Type: `config`

Sends all HTTP errors as `ErrorBuilder` JSON.

Returns: `Boolean`

`default_errorbuilder_forxhr` (default `true`) does the same only for XHR requests. `default_errorbuilder_status` (default `400`) is the HTTP status code of `ErrorBuilder` responses.

Default: `false`.

Example: In the config file
```text
default_errorbuilder_errors (bool) : true
```

### default_uid : <value>

Type: `config`

Changes the generator of `UID()`.

Returns: `String`

`r` (or `uidr`) and `f` (or `uidf`) switch to other UID versions. Without a value the default generator is used.

Example: In the config file
```text
default_uid : f
```

### default_crypto : <value>

Type: `config`

A Node.js cipher for `ENCRYPT()` and `DECRYPT()`.

Returns: `String`

When set, the functions use `crypto.createCipheriv()` with this algorithm and `default_crypto_iv` (a hex string in the file; by default derived from the machine). Without a value Total.js uses its own encryption with `secret`.

Example: In the config file
```text
default_crypto    : aes-256-cbc
default_crypto_iv : 000102030405060708090a0b0c0d0e0f
```

### default_image_converter : gm

Type: `config`

The command-line tool for `Image`.

Returns: `String`

`gm` is GraphicsMagick and `im` is ImageMagick. `default_image_consumption` (default `0`, disabled) limits the memory and map resources of the tool; the value is a percentage of 1500 MB of memory and 3000 MB of map.

Default: `gm`.

Example: In the config file
```text
default_image_converter   : im
default_image_consumption : 50
```

### default_tms_url : /$tms/

Type: `config`

The WebSocket endpoint of the Total.js Message Service.

Returns: `String`

Used when `allow_tms` is `true`. `default_tms_maxlength` (default `1024`, in kB) sets the maximum message size. `secret_tms` is the token that clients must send; without it the endpoint accepts every client.

Default: `/$tms/`.

Example: In the config file
```text
allow_tms       : true
default_tms_url : /$tms/
secret_tms      : my-token
```

### default_interval_clear_cache : 10

Type: `config`

Intervals of the internal service.

- `default_interval_clear_cache` (default `10`): minutes between cleaning of expired cache items and unused sessions.
- `default_interval_clear_resources` (default `20`): minutes between clearing of the loaded resources.
- `default_interval_clear_dnscache` (default `30`): minutes between cleaning of the DNS cache.
- `default_interval_websocket_ping` (default `20000`): milliseconds between WebSocket pings; values under `1000` mean `20000`.

All are parsed as integers.

Example: In the config file
```text
default_interval_clear_cache    : 5
default_interval_websocket_ping : 30000
```

### directory_public : /public/

Type: `config`

Paths of the application directories.

Each directory has a key, relative to the root: `directory_controllers`, `directory_definitions`, `directory_views`, `directory_public`, `directory_schemas`, `directory_models`, `directory_actions`, `directory_modules`, `directory_plugins`, `directory_resources`, `directory_databases`, `directory_logs`, `directory_temp`, `directory_themes`, `directory_components`, `directory_middleware`, `directory_packages`, `directory_flowstreams`, `directory_jsonschemas`, `directory_operations`, `directory_tasks`, `directory_extensions`, `directory_builds`, `directory_workers`, `directory_private`, `directory_configs`, `directory_tests` and others. The default value is the name with slashes, for example `/public/`. The `PATH.*()` methods use these keys.

Without `directory_temp`, a folder in the system temp directory is used. The directories are read when the application starts.

Example: In the config file
```text
directory_public    : /www/
directory_databases : /data/
```

### static_url_script : /js/

Type: `config`

URL prefixes of static files.

Used by the view helpers for static files: `static_url` (default empty, a prefix for all of them, for example a CDN), `static_url_script` (`/js/`), `static_url_style` (`/css/`), `static_url_image` (`/img/`), `static_url_video` (`/videos/`), `static_url_font` (`/fonts/`), `static_url_download` (`/download/`) and `static_url_components` (`/components.`).

Example: In the config file
```text
static_url        : https://cdn.example.com
static_url_script : /scripts/
```

### static_accepts : jpg, png, css, js

Type: `config`

File extensions served as static files.

The default list contains common extensions (images, scripts, styles, fonts, documents, media). In the file, `static_accepts` replaces the whole list; `static_accepts_custom` adds extensions to it.

Example: Add extensions
```text
static_accepts_custom : glb, gltf
```

### allow_websocket : true

Type: `config`

Enables WebSocket routes.

Returns: `Boolean`

`allow_websocket_compression` (default `true`) enables the `permessage-deflate` extension.

Default: `true`.

Example: In the config file
```text
allow_websocket : false
```

### allow_static_files : true

Type: `config`

Serves static files from `public/`.

Returns: `Boolean`

Set to `false` when another server delivers static files.

Default: `true`.

Example: In the config file
```text
allow_static_files : false
```

### allow_gzip : true

Type: `config`

Compresses responses with gzip.

Returns: `Boolean`

Applies to compressible content types when the client accepts gzip.

Default: `true`.

Example: In the config file
```text
allow_gzip : false
```

### allow_compile : true

Type: `config`

Minifies static files and HTML.

Returns: `Boolean`

`allow_compile_script`, `allow_compile_style` and `allow_compile_html` (all `true`) switch the minification of JavaScript, CSS and HTML separately.

Default: `true`.

Example: In the config file
```text
allow_compile_html : false
```

### allow_tms : false

Type: `config`

Enables the Total.js Message Service endpoint.

Returns: `Boolean`

The endpoint is `default_tms_url` and is protected by `secret_tms`.

Default: `false`.

Example: In the config file
```text
allow_tms : true
```

### allow_reqlimit : 0

Type: `config`

The maximum number of concurrent requests from one IP address.

Returns: `Number`

Requests over the limit get `503 Service Unavailable`. `0` disables the limit.

Default: `0`.

Example: In the config file
```text
allow_reqlimit (number) : 20
```

### allow_ssc_validation : true

Type: `config`

Validates TLS certificates of outgoing requests.

Returns: `Boolean`

`false` sets `NODE_TLS_REJECT_UNAUTHORIZED` to `0` and accepts self-signed certificates.

Default: `true`.

Example: In the config file
```text
allow_ssc_validation : false
```

### allow_cache_snapshot : false

Type: `config`

Saves the cache to a file and loads it after a restart.

Returns: `Boolean`

`allow_cache_cluster` (default `false`) synchronizes the cache between cluster instances.

Default: `false`.

Example: In the config file
```text
allow_cache_snapshot : true
```

### allow_totalapi : true

Type: `config`

Enables calls to Total API.

Returns: `Boolean`

The token is read from `totalapi` or `secret_totalapi`. `allow_totalapilogger` (default `false`) sends logs to Total API. `default_tapi` (default `eu`) selects the server.

Default: `true`.

Example: In the config file
```text
totalapi       : my-token
allow_totalapi : true
```

### mail_smtp : smtp.example.com

Type: `config`

The SMTP server used by `MAIL()` and `Mail.send()`.

Related keys:

- `mail_smtp_options`: the options of the SMTP connection, a JavaScript object written as text, for example `{ port: 465, secure: true, user: '...', password: '...' }`;
- `mail_from`: the sender address, the sender name is `name`;
- `mail_reply`: the reply-to address;
- `mail_cc` and `mail_bcc`: copies of every message;
- `mail_smtp_keepalive` (default `10 minutes`): how long the connection stays open;
- `mail_api`: sends emails through Total API (`true` uses the `totalapi` token).

`mail_address_from`, `mail_address_reply` and `mail_address_copy` are older names of `mail_from`, `mail_reply` and `mail_bcc`.

Example: In the config file
```text
mail_smtp         : smtp.example.com
mail_smtp_options : { port: 465, secure: true, user: 'info@example.com', password: 'secret' }
mail_from         : info@example.com
mail_reply        : support@example.com
```

### logger : <value>

Type: `config`

Writes the console output to `logs/debug.log`.

Returns: `Boolean`

`console.log`, `console.warn`, `console.error` and the timers are redirected to the file.

Example: In the config file
```text
logger : true
```

### nosourcemap : false

Type: `config`

Disables source maps.

Returns: `Boolean`

Source maps are generated only in debug mode; in release mode this key is always `true`.

Default: `false`.

Example: In the config file
```text
nosourcemap : true
```

### node_modules : node_modules

Type: `config`

The directory of NPM modules.

Returns: `String`

Used by `NPMINSTALL()` and `F.require()`. A value starting with `~` is an absolute path.

Default: `node_modules`.

Example: In the config file
```text
node_modules : ~/opt/shared/node_modules
```

### security.txt : Contact: mailto:support@totaljs.com

Type: `config`

The content of `/security.txt`.

Returns: `String`

In the file, lines are separated by commas. An empty value disables the response. Read it as `CONF['security.txt']`.

Default: `Contact: mailto:support@totaljs.com`.

Example: In the config file
```text
security.txt : Contact: mailto:security@example.com, Expires: 2026-12-31T00:00:00.000Z
```
