Snippets

What Snippets Are

Snippets are reusable pieces of JavaScript you define once and pull into your check scripts with require(). Instead of pasting the same helper function, token-signing logic, or setup code into every check, you save it as a snippet and require it by name — update it in one place and every check that uses it picks up the change.

A snippet is just a small JavaScript module. Whatever it exports with module.exports becomes available wherever you require it:

require('./snippets/name');

Snippets are scoped to your team, so everyone on the team can require the same helpers from their checks.

Manage Snippets

Open the Snippets page to create, edit, and delete snippets.

Create a Snippet

  1. Click New Snippet.
  2. Enter a Snippet Name — this is the name you'll require in your scripts (for example auth or format-date). Names may contain letters, numbers, hyphens, and underscores only.
  3. Write your JavaScript in the editor. Export whatever you want to reuse with module.exports.
  4. Click Save Snippet.

Each snippet name must be unique within your team.

Edit or Delete a Snippet

Use the row actions on the Snippets page to update a snippet's code or remove it. If a snippet is currently referenced by one or more checks, LoadFocus warns you before you save or delete it, because the change affects every check that requires it. Updating a snippet takes effect on the next run of any check that uses it.

Use a Snippet in a Check Script

Require a snippet by name from the ./snippets/ path inside a check script:

const auth = require('./snippets/auth');

The value you get back is whatever the snippet exports.

Example

Create a snippet named auth that builds an Authorization header:

// snippet: auth
module.exports = function bearer(token) {
return { Authorization: 'Bearer ' + token };
};

Then use it from a check script:

const bearer = require('./snippets/auth');
const headers = bearer(process.env.API_TOKEN);
// pass `headers` into your request

You can keep any reusable logic in a snippet — request signing, payload builders, date and string helpers, or shared assertions — and require it from as many checks as you need.

Snippets vs. Variables and Secrets

Use Snippets for reusable code — helper functions and logic shared across check scripts.

Use Variables for reusable values such as base URLs and account ids, referenced with {{VARIABLE_NAME}}.

Use Secrets for sensitive values such as API tokens and passwords. Secrets are write-only in the UI and referenced with {{SECRET_NAME}}.

Tip: keep sensitive values in Secrets, not hard-coded in a snippet. Pass them into your snippet's functions at run time instead.