Navigation

Function Configuration Files

app/
└── functions/
├── config.json
├── <function>.js
└── <directory>/
└── <function>.js

Every function in your app has a corresponding metadata entry in the function manifest file: /functions/config.json.

Tip

Realm automatically adds functions to the manifest on import if they don't already have a configuration defined. If you're okay with the default settings, you can skip defining the configuration for a function and let Realm do it for you. The manifest will include the generated configurations the next time you export or pull your app.

functions/config.json
[
{
"name": "<Function Name>",
"private": <Boolean>,
"can_evaluate": { <JSON Expression> },
"disable_arg_logs": <Boolean>,
"run_as_system": <Boolean>,
"run_as_user_id": "<Realm User ID>",
"run_as_user_id_script_source": "<Function Source Code>"
},
...
]
Field
Description
name
String
The name of the function. The name must match the file name of a source code file and be unique among all functions in your application.
private
Boolean
If true, this function may only be accessed from incoming webhooks, rules, and named functions. You cannot call a private function directly from a client application or with an SDK.
can_evaluate
JSON Expression (default: true)
A JSON expression that evaluates to true if the function is allowed to execute. Realm evaluates this expression for every incoming request.
disable_arg_logs
Boolean
If true, Realm omits the arguments provided to the function from the function execution log entry.
run_as_system
Boolean
If true, this function runs as the system user. This overrides any values defined for run_as_user_id and run_as_user_id_script_source.
run_as_user_id
String
The unique ID of a Realm User that the function always executes as. Cannot be used with run_as_user_id_script_source.
run_as_user_id_script_source
String
A stringified function that runs whenever the function is called and returns the unique ID of a Realm User that the function executes as. Cannot be used with run_as_user_id.

You define a function's source code in a .js file within the /functions directory that uses the function name as its file name. Each file must export the main function that runs whenever a request calls the function.

Important

You can organize source code files by defining arbitrary subdirectories within /functions. However, Realm identifies each function's source code strictly by file name, so all .js files must have unique names, even if they are in different directories.

/functions/<function name>.js
exports = function addOne(input) {
if(typeof input !== "number") {
throw new Error("You must call addOne() with a number");
}
return input + 1;
};
Give Feedback