Spanish Total.js
English
Documentation For AI agents
Contents

Configuration

CONF, LOADCONFIG(), DEBUG and every $ key of the framework with its default.

.md GitHub
On this page

Every key the framework reads from CONF, with its type and default, plus CONF, LOADCONFIG(), DEBUG and the $reconfigure event. The guide Configuration explains the format of the config file, the types, .env and the loading order.

API

property

CONF

The global object with the configuration of the application.

Returns Object

Holds the defaults of the framework and every key loaded from the options of F.http(), the config file, plugin config files and LOADCONFIG(). F.config is the same object. Read it anywhere; write to it with LOADCONFIG() when the change must refresh derived settings.

Read values
exports.install = function() {
	ROUTE('GET /about/', function($) {
		$.json({ name: CONF.name, version: CONF.version });
	});
};
method

LOADCONFIG(value)

Applies configuration values at runtime.
ParameterTypeDescription
value String|Object|Array The text of a config file, an object of keys and values, or an array of { id, type, value } items (key/name and val/body are accepted too).

Parses value like the config file and copies the keys into CONF. In an object or an array, the values false, 0 and '' are stored as undefined. Special keys are processed: $root is normalized and prefixes $api, $timezone sets process.env.TZ, $port becomes a number, $httpfiles adds extensions, $cryptoiv becomes a Buffer, smtp/mail/mail_smtp/mail_smtp_options build CONF.smtp, totalapi sets the Total API token. Then it refreshes the directories, the logger ($logger), the CORS list and TMS, and emits $reconfigure. The framework calls it for the config file itself.

Text
LOADCONFIG('$httptimeout (number) : 15\nmaintenance : true');
Array with types
LOADCONFIG([
	{ id: 'limit', type: 'number', value: '25' },
	{ id: 'tags', type: 'array', value: 'a, b, c' }
]);
Object
LOADCONFIG({ name: 'Shop', $cors: 'https://shop.example.com' });
property

DEBUG

true in debug mode, false in release mode.

Returns Boolean

A global boolean. It starts as process.env.NODE_ENV !== 'production'. The debug runner sets it to true and the release runner sets it to false before the application loads, so NODE_ENV decides the mode when the application calls F.http() or F.load() without a runner. The framework uses it for caching of views and static files, minification and the source map ($sourcemap follows it).

Conditional code
if (DEBUG)
	console.log('Debug mode');
event

ON('$reconfigure', function() {})

Emitted after LOADCONFIG() applies new values.

Emitted at the end of every LOADCONFIG() call, including the load of the config file at start. Use it to refresh your own objects that depend on configuration values.

Refresh a client
ON('$reconfigure', function() {
	MAIN.client = createclient(CONF.service_url);
});
config

totalapi : String|Boolean

since 0.0.16 Sets the Total API token or turns Total API on or off.

Returns String|Boolean

A string longer than five characters is stored as CONF.secret_totalapi, the token for API('TAPI', ...) and TotalAPI() calls. Any other value is stored as $tapi.

In the config file
totalapi : your-total-api-token
config

$root : String

A URL prefix for the whole application.

Returns String

Normalized to start and end with /. Route URLs get the prefix (API routes through $api), static files are served under it and F.virtualpath() adds it. Use it when the application runs under a sub-path behind a proxy.

Default: ''.

In the config file
$root : /app/
config

$api : String

The default API endpoint.

Returns String

A ? in a route URL is replaced with this value, so ROUTE('API ?/users/ ...') listens on /api/users/. With $root, the prefix is added to it.

Default: '/api/'.

In the config file
$api : /v1/
config

$mcp : Boolean

Turns on the MCP server.

Returns Boolean

true creates the route POST /$mcp/, where AI clients list and call the actions that have mcp: true. The route is created when the application is ready, so set the key in the config file or before the start. See MCP server.

Default: false.

In the config file
$mcp : true
config

$cors : String

Origins allowed for cross-origin requests.

Returns String

* allows every origin. Otherwise a list of origins separated by ,, ; or |, compared with the Origin header (for example https://app.example.com). An item that starts with * matches every origin that contains the rest (*example.com). Requests from the same host are always allowed; other origins get the error 400. CORS() changes the value in code; see Routing.

Default: ''.

In the config file
$cors : https://app.example.com, *example.org
config

$port : Number

The port of the HTTP server.

Returns Number

The value is converted to a number. Leave the key out for the automatic port: the port option of F.http(), the PORT environment variable, the first 3-5 digit number in the command line arguments, or 8000.

Default: 'auto'.

In the config file
$port : 8000
config

$ip : String

The IP address the HTTP server listens on.

Returns String

The ip option of F.http() overrides it. Use 127.0.0.1 to accept only local connections.

Default: '0.0.0.0'.

In the config file
$ip : 127.0.0.1
config

$unixsocket : String

A Unix socket path for the HTTP server.

Returns String

When set (or when F.http() gets the unixsocket option), the server listens on the socket instead of a port.

Default: ''.

In the config file
$unixsocket : /var/run/app.sock
config

$timezone : String

The time zone of the process.

Returns String

Copied into process.env.TZ, so all Date values of the process use it.

Default: 'utc'.

In the config file
$timezone : Europe/Bratislava
config

$insecure : Boolean

Accepts invalid TLS certificates in outgoing requests.

Returns Boolean

Sets process.env.NODE_TLS_REJECT_UNAUTHORIZED to 0 when true and 1 otherwise. Use it only for development against self-signed servers.

Default: false.

In the config file
$insecure : true
config

$performance : Boolean

Tunes the HTTP sockets for many connections.

Returns Boolean

Sets maxSockets of the global HTTP agent to 9999 and turns on setNoDelay and keep-alive for incoming connections.

Default: false.

In the config file
$performance : true
config

$httpreqlimit : Number

The maximum number of requests per IP address per minute.

Returns Number

0 turns the limit off. Above the limit, requests get the error 503 until the counters are cleared at the next minute.

Default: 0.

In the config file
$httpreqlimit (number) : 300
config

$blacklist : String

Blocked IP addresses.

Returns String

A string of IP addresses, for example separated by commas. HTTP requests from an IP address found in it get the error 400, and WebSocket connections from it are closed.

Default: ''.

In the config file
$blacklist : 10.0.0.5, 10.0.0.6
config

$httpcompress : Boolean

Compresses responses with gzip.

Returns Boolean

When the client accepts gzip, text responses larger than 256 bytes and compressible static files are compressed.

Default: true.

In the config file
$httpcompress : false
config

$httpetag : String

A value added to the ETag of static files and cached responses.

Returns String

When empty, it is created from CONF.version without dots and spaces, so a new version invalidates browser caches.

Default: ''.

In the config file
$httpetag : build42
config

$httpmaxsize : Number

The maximum size of a request body in kB.

Returns Number

The default limit of every HTTP route without its own limit.

Default: 256.

In the config file
$httpmaxsize (number) : 1024
config

$httprangebuffer : Number

The size of one chunk of a range response in kB.

Returns Number

Used for Range requests of static files (video, audio) when the client does not give the end.

Default: 5120.

In the config file
$httprangebuffer (number) : 2048
config

$httptimeout : Number

The request timeout in seconds.

Returns Number

A route can set its own timeout. Requests are checked every five seconds.

Default: 5.

In the config file
$httptimeout (number) : 10
config

$httpfiles : String

File extensions served as static files.

Returns String

In the config file, a comma-separated list of extensions that are added to the defaults (jpg, png, css, js, json, pdf, mp4 and many more). In code it is an object with true for every allowed extension.

Default: common web extensions.

In the config file
$httpfiles : glb, gltf
config

$httpchecktypes : Boolean

Checks the content type of uploaded files.

Returns Boolean

For multipart/form-data only. false skips the check.

Default: true.

In the config file
$httpchecktypes : false
config

$httpmaxage : Number

The max-age of cached responses in seconds.

Returns Number

Used in the Cache-Control header of static files and of responses cached with controller.httpcache().

Default: 60.

In the config file
$httpmaxage (number) : 300
config

$httpmaxkeys : Number

Limits of URL-encoded data.

Returns Number

$httpmaxkeys is the maximum number of keys parsed from a query string or URL-encoded body. $httpmaxkey (default 25) is the maximum length of one key; longer keys are dropped.

Default: 33.

In the config file
$httpmaxkeys (number) : 100
$httpmaxkey (number)  : 50
config

$httpcacheoffset : String

since 0.0.16 Moves the Last-Modified date of static files.

Returns String

A time offset in the format of Date.add(), for example 1 minute or -5 minutes. It is added to the modification time of the file in the Last-Modified header.

Default: ''.

In the config file
$httpcacheoffset : 1 minute
config

$xpoweredby : String

The value of the X-Powered-By header.

Returns String

An empty value removes the header.

Default: 'Total.js'.

In the config file
$xpoweredby : 
config

$minify* : Boolean

Minification of JavaScript, CSS and HTML.

Returns Boolean

$minifyjs, $minifycss and $minifyhtml (all true by default) turn the minification of static .js and .css files, inline code and rendered HTML on or off.

In the config file
$minifyhtml : false
$minifyjs   : true
$minifycss  : true
config

$filtererrors : Boolean

Ignores harmless uncaught errors.

Returns Boolean

Uncaught EPIPE, invalid distance and ERR_IPC_CHANNEL_CLOSED errors are not logged.

Default: true.

In the config file
$filtererrors : false
config

$cleartemp : Boolean

Clears the tmp directory at start.

Returns Boolean

Deletes the .js, .css, .html, .htm, .tmp and .upload files of the tmp directory when the application loads.

Default: true.

In the config file
$cleartemp : false
config

$customtitles : Boolean

Turns off the automatic suffix of page titles.

Returns Boolean

By default a view title on pages other than / gets - and CONF.name appended. true keeps the title as you set it.

Default: false.

In the config file
$customtitles : true
config

$clearcache : Number

How often internal caches are cleared, in minutes.

Returns Number

Clears the caches of actions, paths, views, images, templates, query builders and file storages.

Default: 10.

In the config file
$clearcache (number) : 30
config

$imageconverter : String

The program used by the image module.

Returns String

gm for GraphicsMagick, im for the ImageMagick convert command or magick for ImageMagick 7. See Images.

Default: 'gm'.

In the config file
$imageconverter : magick
config

$stats : Boolean

Writes the statistics file of the application.

Returns Boolean

Every minute the framework writes the usage statistics to <main script>.json (for example index.js.json). F.load() with a list of types without stats turns it off.

Default: true.

In the config file
$stats : false
config

$sourcemap : Boolean

Writes the source map of the application.

Returns Boolean

Writes routes, actions, schemas and plugins to <main script>.map for tools. The framework sets it to the value of DEBUG when it loads all parts, and to false when F.load() gets a list of types without stats.

Turn off
$sourcemap : false
config

$npmcache : String

The npm cache directory for NPMINSTALL().

Returns String

Passed to npm as NPM_CONFIG_CACHE.

Default: '/var/www/.npm'.

In the config file
$npmcache : /tmp/.npm
config

$nodemodules : String

The directory of installed npm modules.

Returns String

NPMINSTALL() installs into it and REQUIRE() loads from it when a normal require() fails.

Default: '<root>/node_modules'.

In the config file
$nodemodules : /www/shared/node_modules
config

$python : String

The Python command.

Returns String

Used by F.python() and F.pipinstall(). PYPELINE() always runs python3.

Default: 'python3'.

In the config file
$python : /usr/bin/python3.12
config

$shell : String

The shell for SHELL().

Returns String

When set, SHELL() runs commands in this shell instead of the default one.

Default: ''.

In the config file
$shell : /bin/bash
config

$wsmaxsize : Number

The maximum size of a WebSocket message in kB.

Returns Number

The default limit of every WebSocket route without its own limit.

Default: 256.

In the config file
$wsmaxsize (number) : 1024
config

$wscompress : Boolean

Compresses WebSocket messages.

Returns Boolean

Uses permessage-deflate when the client supports it.

Default: true.

In the config file
$wscompress : false
config

$wsencodedecode : Boolean

URL-encodes WebSocket messages.

Returns Boolean

true encodes outgoing messages with encodeURIComponent and decodes incoming ones.

Default: false.

In the config file
$wsencodedecode : true
config

$wsmaxlatency : Number

The maximum ping latency of a WebSocket client in milliseconds.

Returns Number

When the framework pings the connections, clients without an answer or with a higher latency are closed.

Default: 2000.

In the config file
$wsmaxlatency (number) : 5000
config

$proxytimeout : Number

The timeout of proxied requests in seconds.

Returns Number

Used by PROXY() routes without their own timeout.

Default: 5.

In the config file
$proxytimeout (number) : 30
config

$proxyrequest : String

A proxy server for outgoing requests.

Returns String

REQUEST() and the builders that use it send requests through this proxy (host:port, http://host:port). Requests to localhost and 127.0.0.1 go directly.

Default: not set.

In the config file
$proxyrequest : http://proxy.local:3128
config

$cookie* : String|Boolean

Defaults of cookies.

Returns String|Boolean

$cookiesamesite (default Lax) is the SameSite value of cookies without their own. $cookiesecure (default false) adds Secure to cookies that do not set secure.

In the config file
$cookiesamesite : Strict
$cookiesecure   : true
config

$csrfexpiration : String

The lifetime of CSRF tokens.

Returns String

A time in the format of Date.add(). Tokens are created only when secret_csrf is set.

Default: '30 minutes'.

In the config file
$csrfexpiration : 2 hours
config

$crypto : String

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

Returns String

When set (for example aes-256-cbc), ENCRYPT() and DECRYPT() use crypto.createCipheriv() with the key you pass and $cryptoiv as the IV; the key must have the length the cipher needs. $cryptoiv is created from a hash of the system; in the config file give it as hex or base64 and it becomes a Buffer.

Default: not set.

In the config file
$crypto   : aes-256-cbc
$cryptoiv : 000102030405060708090a0b0c0d0e0f
config

$tapi* : Boolean|String

Total API settings.

Returns Boolean|String

$tapi (default true) allows API('TAPI', ...) calls; with false every operation except check fails with totalapi_inactive. $tapiurl (default eu) is the region in https://<region>.api.totaljs.com/. The token is secret_totalapi; $tapisecret is read as a fallback. $tapimail : true sends the e-mails through the Total API instead of SMTP (see Sending email) and $tapilogger : true sends the audit records there (see Audit logs); both are false by default.

In the config file
secret_totalapi : your-token
$tapiurl        : eu
config

$tms* : Boolean|String|Number

Total.js Message Service settings.

Returns Boolean|String|Number

$tms (default false) opens the TMS WebSocket endpoint $tmsurl (default /$tms/). $tmsmaxsize (default 256) is the message limit in kB, $tmsclearblocked (default 60) clears blocked clients every N minutes, and secret_tms is the token clients must send. See Message Service (TMS).

In the config file
$tms       : true
secret_tms : my-secret
config

$imprint : Boolean

Prints the start screen.

Returns Boolean

false hides the information block (name, version, Node.js, URL) printed when the application starts.

Default: true.

In the config file
$imprint : false
config

$logger : Boolean

Writes console output to logs/debug.log.

Returns Boolean

true redirects console.log, console.warn, console.error, console.time and console.timeEnd to the file logs/debug.log.

Default: false.

In the config file
$logger : true
config

$dir* : String

Custom paths of the application directories.

Returns String

$dir + the name of a directory sets its absolute path: $dirpublic, $dirtmp, $dirlogs, $dirdatabases, $dirviews, $dirplugins, $dirmodules, $dirresources, $dirtemplates, $dirprivate and the others. PATH.public(), PATH.databases() and the loaders use them.

In the config file
$dirpublic    : /www/cdn/public
$dirdatabases : /data/app
Made in Europe