Configuration
The CONF object, every built-in config key and the functions for loading configuration.
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.
CONFReturns 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.
exports.install = function() {
ROUTE('GET /api/info/', info);
};
function info() {
this.json({ name: CONF.name, version: CONF.version });
}
<footer>@{CONF.name} v@{CONF.version}</footer>
method
LOADCONFIG(value)
Merges new values into CONF at runtime.
LOADCONFIG(value)| Parameter | Type | Description |
|---|---|---|
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 }(keyornameinstead ofid,bodyinstead ofvalue).
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.
// Items stored e.g. in a database: [{ id, type, value }]
function applysettings(items) {
LOADCONFIG(items);
}
LOADCONFIG({ allow_tms: true, secret_tms: 'token' });
LOADCONFIG('name : My Shop\nlimit (number) : 50');
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.
DEBUGReturns Boolean
In debug mode Total.js reads config-debug and .env-debug; otherwise config-release and .env-release.
if (DEBUG)
console.log('Running with config-debug');
property
RELEASE
true when the application runs in release mode.
RELEASEReturns 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.
if (RELEASE)
CONF.allow_tms = true;
method
String.parseConfig([def], [onerr])
Parses text in the config syntax into an object.
String.parseConfig([def], [onerr])| Parameter | Type | Description |
|---|---|---|
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.
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.
String.parseENV()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.
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.
KEY=valueTotal.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.
DATABASE_URL=postgresql://user:pass@localhost:5432/shop
PORT=8000
database (env) : DATABASE_URL
default_port : auto
method
PATH.configs([filename])
Returns the path to a file in the configs directory.
PATH.configs([filename])| Parameter | Type | Description |
|---|---|---|
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.
var menu = require('fs').readFileSync(PATH.configs('menu.json')).toString('utf8').parseJSON();
config
name : Total.js
The name of the application.
name : Total.jsReturns 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.
name : My Shop
config
version : 1.0.0
The version of the application.
version : 1.0.0Returns 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.
version : 2.1.0
config
url : <value>
The public URL of the application.
url : <value>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.
url : https://www.example.com
config
secret : <value>
The key used by ENCRYPT() and DECRYPT().
secret : <value>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.
secret : my-long-random-secret
config
secret_uid : <value>
A value that makes the generated UID() values unique for the application.
secret_uid : <value>Returns String
Without a value Total.js computes it from name.
secret_uid : shop
config
secret_encryption : null
Enables encryption of request and response bodies.
secret_encryption : nullReturns 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.
secret_encryption : my-encryption-key
config
secret_csrf : null
Enables CSRF tokens.
secret_csrf : nullReturns 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.
secret_csrf : my-csrf-key
default_csrf_maxage : 30 minutes
config
default_root : <value>
The URL prefix when the application runs in a subdirectory.
default_root : <value>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.
default_root : /shop/
config
default_port : <value>
The HTTP port.
default_port : <value>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.
default_port : auto
default_ip : 127.0.0.1
config
default_timezone : utc
The time zone of the process.
default_timezone : utcReturns String
Assigned to process.env.TZ when the config is loaded.
Default: utc.
default_timezone : Europe/Berlin
config
default_theme : <value>
The default theme.
default_theme : <value>Returns String
The name of a folder in themes/ used by views and static files when no theme is set.
default_theme : default
config
default_request_maxlength : 10
The maximum size of a request body, in kilobytes.
default_request_maxlength : 10Returns Number
Applies to routes without their own length. Parsed as an integer.
Default: 10.
default_request_maxlength : 1024
config
default_request_timeout : 3000
The request timeout, in milliseconds.
default_request_timeout : 3000Returns Number
Applies to routes without their own timeout. Parsed as an integer.
Default: 3000.
default_request_timeout : 10000
config
default_request_maxkeys : 33
The maximum number of keys parsed from a query string or a URL-encoded body.
default_request_maxkeys : 33Returns Number
Extra keys are ignored. default_request_maxkey (default 25) is the maximum length of one key.
Default: 33.
default_request_maxkeys : 50
config
default_restbuilder_timeout : 10000
The default timeout of RESTBuilder and REQUEST(), in milliseconds.
default_restbuilder_timeout : 10000Returns 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.
default_restbuilder_timeout : 30000
config
default_websocket_maxlength : 2
The maximum size of a WebSocket message, in kilobytes.
default_websocket_maxlength : 2Returns Number
Applies to WebSocket routes without their own length.
Default: 2.
default_websocket_maxlength : 64
config
default_websocket_maxlatency : 2000
The maximum latency of a WebSocket client, in milliseconds.
default_websocket_maxlatency : 2000Returns Number
Total.js pings clients every default_interval_websocket_ping milliseconds and closes clients with a higher latency. 0 disables the pinging.
Default: 2000.
default_websocket_maxlatency : 5000
config
default_cors : null
Allowed origins for cross-origin requests.
default_cors : nullReturns 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.
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.
default_response_maxage : 11111111Returns String
Used only in release mode.
Default: 11111111.
default_response_maxage : 86400
config
default_cookies_samesite : Lax
The default SameSite attribute of cookies.
default_cookies_samesite : LaxReturns 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.
default_cookies_samesite : Strict
default_cookies_secure : true
config
default_errorbuilder_errors : false
Sends all HTTP errors as ErrorBuilder JSON.
default_errorbuilder_errors : falseReturns 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.
default_errorbuilder_errors (bool) : true
config
default_uid : <value>
Changes the generator of UID().
default_uid : <value>Returns String
r (or uidr) and f (or uidf) switch to other UID versions. Without a value the default generator is used.
default_uid : f
config
default_crypto : <value>
A Node.js cipher for ENCRYPT() and DECRYPT().
default_crypto : <value>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.
default_crypto : aes-256-cbc
default_crypto_iv : 000102030405060708090a0b0c0d0e0f
config
default_image_converter : gm
The command-line tool for Image.
default_image_converter : gmReturns 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.
default_image_converter : im
default_image_consumption : 50
config
default_tms_url : /$tms/
The WebSocket endpoint of the Total.js Message Service.
default_tms_url : /$tms/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/.
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 : 10default_interval_clear_cache(default10): minutes between cleaning of expired cache items and unused sessions.default_interval_clear_resources(default20): minutes between clearing of the loaded resources.default_interval_clear_dnscache(default30): minutes between cleaning of the DNS cache.default_interval_websocket_ping(default20000): milliseconds between WebSocket pings; values under1000mean20000.
All are parsed as integers.
default_interval_clear_cache : 5
default_interval_websocket_ping : 30000
config
directory_public : /public/
Paths of the application directories.
directory_public : /public/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.
directory_public : /www/
directory_databases : /data/
config
static_url_script : /js/
URL prefixes of static files.
static_url_script : /js/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.).
static_url : https://cdn.example.com
static_url_script : /scripts/
config
static_accepts : jpg, png, css, js
File extensions served as static files.
static_accepts : jpg, png, css, jsThe 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.
static_accepts_custom : glb, gltf
config
allow_websocket : true
Enables WebSocket routes.
allow_websocket : trueReturns Boolean
allow_websocket_compression (default true) enables the permessage-deflate extension.
Default: true.
allow_websocket : false
config
allow_static_files : true
Serves static files from public/.
allow_static_files : trueReturns Boolean
Set to false when another server delivers static files.
Default: true.
allow_static_files : false
config
allow_gzip : true
Compresses responses with gzip.
allow_gzip : trueReturns Boolean
Applies to compressible content types when the client accepts gzip.
Default: true.
allow_gzip : false
config
allow_compile : true
Minifies static files and HTML.
allow_compile : trueReturns Boolean
allow_compile_script, allow_compile_style and allow_compile_html (all true) switch the minification of JavaScript, CSS and HTML separately.
Default: true.
allow_compile_html : false
config
allow_tms : false
Enables the Total.js Message Service endpoint.
allow_tms : falseReturns Boolean
The endpoint is default_tms_url and is protected by secret_tms.
Default: false.
allow_tms : true
config
allow_reqlimit : 0
The maximum number of concurrent requests from one IP address.
allow_reqlimit : 0Returns Number
Requests over the limit get 503 Service Unavailable. 0 disables the limit.
Default: 0.
allow_reqlimit (number) : 20
config
allow_ssc_validation : true
Validates TLS certificates of outgoing requests.
allow_ssc_validation : trueReturns Boolean
false sets NODE_TLS_REJECT_UNAUTHORIZED to 0 and accepts self-signed certificates.
Default: true.
allow_ssc_validation : false
config
allow_cache_snapshot : false
Saves the cache to a file and loads it after a restart.
allow_cache_snapshot : falseReturns Boolean
allow_cache_cluster (default false) synchronizes the cache between cluster instances.
Default: false.
allow_cache_snapshot : true
config
allow_totalapi : true
Enables calls to Total API.
allow_totalapi : trueReturns 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.
totalapi : my-token
allow_totalapi : true
config
mail_smtp : smtp.example.com
The SMTP server used by MAIL() and Mail.send().
mail_smtp : smtp.example.comRelated 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 isname;mail_reply: the reply-to address;mail_ccandmail_bcc: copies of every message;mail_smtp_keepalive(default10 minutes): how long the connection stays open;mail_api: sends emails through Total API (trueuses thetotalapitoken).
mail_address_from, mail_address_reply and mail_address_copy are older names of mail_from, mail_reply and mail_bcc.
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.
logger : <value>Returns Boolean
console.log, console.warn, console.error and the timers are redirected to the file.
logger : true
config
nosourcemap : false
Disables source maps.
nosourcemap : falseReturns Boolean
Source maps are generated only in debug mode; in release mode this key is always true.
Default: false.
nosourcemap : true
config
node_modules : node_modules
The directory of NPM modules.
node_modules : node_modulesReturns String
Used by NPMINSTALL() and F.require(). A value starting with ~ is an absolute path.
Default: node_modules.
node_modules : ~/opt/shared/node_modules
config
security.txt : Contact: mailto:support@totaljs.com
The content of /security.txt.
security.txt : Contact: mailto:support@totaljs.comReturns 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.
security.txt : Contact: mailto:security@example.com, Expires: 2026-12-31T00:00:00.000Z