Spanish Total.js
English
Documentation For AI agents
Contents

Configuration

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

.md GitHub
On this page

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 explains the syntax, the types and environment variables; this page lists the functions and the built-in keys with their defaults.

API

property

CONF

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.

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

function info() {
	this.json({ name: CONF.name, version: CONF.version });
}
In a view
<footer>@{CONF.name} v@{CONF.version}</footer>
method

LOADCONFIG(value)

Merges new values into CONF at runtime.
ParameterTypeDescription
value Object|String|Array 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.

Settings from a database
// Items stored e.g. in a database: [{ id, type, value }]
function applysettings(items) {
	LOADCONFIG(items);
}
An object or a string
LOADCONFIG({ allow_tms: true, secret_tms: 'token' });
LOADCONFIG('name : My Shop\nlimit (number) : 50');
Typed items
LOADCONFIG([
	{ id: 'limit', type: 'number', value: '50' },
	{ id: 'languages', type: '[string]', value: 'en, sk' },
	{ id: 'newsletter', type: 'boolean', value: 'on' }
]);
property

DEBUG

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.

Mode-specific code
if (DEBUG)
	console.log('Running with config-debug');
property

RELEASE

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.

Release only
if (RELEASE)
	CONF.allow_tms = true;
method

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

Parses text in the config syntax into an object.
ParameterTypeDescription
def? Object Default values, copied into the result first.
onerr? Function 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.

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

String.parseENV()

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.

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

KEY=value

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.

.env
DATABASE_URL=postgresql://user:pass@localhost:5432/shop
PORT=8000
config
database (env) : DATABASE_URL
default_port   : auto
method

PATH.configs([filename])

Returns the path to a file in the configs directory.
ParameterTypeDescription
filename? String 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.

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

name : Total.js

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.

In the config file
name : My Shop
config

version : 1.0.0

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.

In the config file
version : 2.1.0
config

url : <value>

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.

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

secret : <value>

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.

In the config file
secret : my-long-random-secret
config

secret_uid : <value>

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

Returns String

Without a value Total.js computes it from name.

In the config file
secret_uid : shop
config

secret_encryption : null

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.

In the config file
secret_encryption : my-encryption-key
config

secret_csrf : null

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.

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

default_root : <value>

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.

In the config file
default_root : /shop/
config

default_port : <value>

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.

In the config file
default_port : auto
default_ip   : 127.0.0.1
config

default_timezone : utc

The time zone of the process.

Returns String

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

Default: utc.

In the config file
default_timezone : Europe/Berlin
config

default_theme : <value>

The default theme.

Returns String

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

In the config file
default_theme : default
config

default_request_maxlength : 10

The maximum size of a request body, in kilobytes.

Returns Number

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

Default: 10.

In the config file
default_request_maxlength : 1024
config

default_request_timeout : 3000

The request timeout, in milliseconds.

Returns Number

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

Default: 3000.

In the config file
default_request_timeout : 10000
config

default_request_maxkeys : 33

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.

In the config file
default_request_maxkeys : 50
config

default_restbuilder_timeout : 10000

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.

In the config file
default_restbuilder_timeout : 30000
config

default_websocket_maxlength : 2

The maximum size of a WebSocket message, in kilobytes.

Returns Number

Applies to WebSocket routes without their own length.

Default: 2.

In the config file
default_websocket_maxlength : 64
config

default_websocket_maxlatency : 2000

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.

In the config file
default_websocket_maxlatency : 5000
config

default_cors : null

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.

In the config file
default_cors : example.com, app.example.com
config

default_response_maxage : 11111111

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

Returns String

Used only in release mode.

Default: 11111111.

In the config file
default_response_maxage : 86400
config

default_cookies_samesite : Lax

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.

In the config file
default_cookies_samesite : Strict
default_cookies_secure   : true
config

default_errorbuilder_errors : false

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.

In the config file
default_errorbuilder_errors (bool) : true
config

default_uid : <value>

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.

In the config file
default_uid : f
config

default_crypto : <value>

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.

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

default_image_converter : gm

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.

In the config file
default_image_converter   : im
default_image_consumption : 50
config

default_tms_url : /$tms/

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/.

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

default_interval_clear_cache : 10

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.

In the config file
default_interval_clear_cache    : 5
default_interval_websocket_ping : 30000
config

directory_public : /public/

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.

In the config file
directory_public    : /www/
directory_databases : /data/
config

static_url_script : /js/

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.).

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

static_accepts : jpg, png, css, js

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.

Add extensions
static_accepts_custom : glb, gltf
config

allow_websocket : true

Enables WebSocket routes.

Returns Boolean

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

Default: true.

In the config file
allow_websocket : false
config

allow_static_files : true

Serves static files from public/.

Returns Boolean

Set to false when another server delivers static files.

Default: true.

In the config file
allow_static_files : false
config

allow_gzip : true

Compresses responses with gzip.

Returns Boolean

Applies to compressible content types when the client accepts gzip.

Default: true.

In the config file
allow_gzip : false
config

allow_compile : true

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.

In the config file
allow_compile_html : false
config

allow_tms : false

Enables the Total.js Message Service endpoint.

Returns Boolean

The endpoint is default_tms_url and is protected by secret_tms.

Default: false.

In the config file
allow_tms : true
config

allow_reqlimit : 0

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.

In the config file
allow_reqlimit (number) : 20
config

allow_ssc_validation : true

Validates TLS certificates of outgoing requests.

Returns Boolean

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

Default: true.

In the config file
allow_ssc_validation : false
config

allow_cache_snapshot : false

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.

In the config file
allow_cache_snapshot : true
config

allow_totalapi : true

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.

In the config file
totalapi       : my-token
allow_totalapi : true
config

mail_smtp : smtp.example.com

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.

In the config file
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
config

logger : <value>

Writes the console output to logs/debug.log.

Returns Boolean

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

In the config file
logger : true
config

nosourcemap : false

Disables source maps.

Returns Boolean

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

Default: false.

In the config file
nosourcemap : true
config

node_modules : node_modules

The directory of NPM modules.

Returns String

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

Default: node_modules.

In the config file
node_modules : ~/opt/shared/node_modules
config

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

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.

In the config file
security.txt : Contact: mailto:security@example.com, Expires: 2026-12-31T00:00:00.000Z
Made in Europe