FNLB Devs

Developer Portal

Self Hosting

Node.js SDK

The fnlb package is the Node.js and Bun SDK for FNLB. You use it to run bots from your own process: a small script on your laptop, a long-running service, or a self-hosted cluster. This page covers install, authentication, and start() / stop() — how you bring local shard processes online and configure shards. After start(), you work with bots through the SDK itself: listen for events, read and set party meta, send chat, run commands, and call fnlb.api. That is documented in the SDK guides, not only for self-hosting. Any project that calls start() uses the same APIs. The generated symbol reference is the SDK Reference. The machine-readable spec is /sdk.json.

SDK guides

Requirements

  • Node.js 22 or newer (or Bun). The examples use top-level await, so run them as ES modules (.mjs, or a project with "type": "module").
  • An FNLB account with at least one bot. Create and manage bots at app.fnlb.net.
  • An API token or OAuth2 access token — see Authentication.

Installation

npm install fnlb@latest

Using Bun? Install with:

bun install fnlb@latest

Authentication

start() uses your credential to read categories and bots, then opens a gateway connection for the processes it spawns. Pass any supported credential as apiToken or token — the two options are interchangeable.

TypeFormatNotes
API tokenFNLB_...From app.fnlb.net/account. See Authenticating.
OAuth2 access tokenFNLBOA2AT_...Needs the bots.run, categories.read, and bots.read scopes. See OAuth2.
await fnlb.start({
  token: 'FNLBOA2AT_...',
  categories: ['your-category-id']
});

Quick start: one bot

import FNLB from 'fnlb';

const fnlb = new FNLB();

await fnlb.start({
  apiToken: 'your-api-token',
  categories: ['your-category-id']
});

Category ids and bot ids are shown on a bot's page at app.fnlb.net/bots under About this bot, and via GET /categories and GET /bots.

Options reference

Constructor (FNLBConfig)

OptionTypeDescription
clusterNamestringName shown for your cluster in logs and on the gateway.
fnlbPathstringDirectory used for the .fnlb download cache. Defaults to the current working directory.
channel'stable' | 'beta' | 'dev'Default release channel. Defaults to stable.
updateIntervalMsnumberHow often (in milliseconds) the SDK checks for package updates.
maxDownloadRetriesnumberMaximum download retries before giving up.
maxBackoffMsnumberMaximum backoff between retries.
onLogMessage(message: string) => voidCallback for SDK log messages.
onSubProcessLogMessage(message: string) => voidCallback for shard process log messages.
disableLogs / disableErrorLogsbooleanSilence SDK logs, or only the error logs.
disableSubProcessLogs / disableSubProcessErrorLogsbooleanSilence shard stdout and stderr mirroring.
const fnlb = new FNLB({
  clusterName: 'MyAwesomeCluster',
  channel: 'stable',
  onLogMessage: (message) => console.log(message)
});

start() (StartConfig)

OptionTypeDescription
apiToken / tokenstringYour FNLB_... API token or FNLBOA2AT_... OAuth2 access token.
categoriesstring[]Category ids whose bots may run. Omit (or pass []) to allow bots from any category.
botsstring[]Exact bot ids to run.
numberOfShardsnumberNumber of shards (subprocesses) to spawn. Defaults to 1.
botsPerShardnumberMaximum number of bots each shard may run. Defaults to 1.
overrideCategoryConfigobjectPer-category and per-bot config overrides. See Override category settings.
channel'stable' | 'beta' | 'dev'Release channel for this run.
logLevel'INFO' | 'DEBUG'Log verbosity. The LogLevel enum is exported by the SDK.
hideUsernames / hideEmailsbooleanRedact usernames or emails in shard logs.
extraEnvRecord<string, string>Extra environment variables passed to each shard process.

How bot selection works

categories and bots are include lists:

  • Categories only — runs every bot in those categories, plus bots that have no category.
  • Bot ids only — runs only the listed bots.
  • Both — runs the union of the two selections.
  • Neither — runs your full bot pool.

Invalid ids are ignored. Multiple shards can share the same bots list: the gateway assigns each id to exactly one shard, so no bot runs twice. Omit categories (or pass []) when you only want specific bot ids from any category; when categories is set, bots without a category are still included.

Running multiple bots on one shard

botsPerShard sets the maximum number of bots that can run inside a single shard (subprocess).

await fnlb.start({
  apiToken: 'your-api-token',
  categories: ['your-category-id'],
  botsPerShard: 10
});

Scaling with multiple shards

Each shard is its own subprocess. Multiply shards by bots-per-shard to get your capacity ceiling.

await fnlb.start({
  apiToken: 'your-api-token',
  categories: ['your-category-id'],
  numberOfShards: 2,
  botsPerShard: 10 // up to 20 bots total
});

Launching bots across multiple categories

await fnlb.start({
  apiToken: 'your-api-token',
  categories: ['category-id-1', 'category-id-2'],
  numberOfShards: 2,
  botsPerShard: 10
});

Starting specific bots by id

await fnlb.start({
  apiToken: 'your-api-token',
  bots: ['bot-id-1', 'bot-id-2'],
  botsPerShard: 2
});

Bot ids come from a bot's page at app.fnlb.net/bots under About this bot (FNLB ID), or from GET /bots. You can combine bots with categories; the selection is the union of both lists. Multiple shards may share the same bots list without starting a bot twice.

Override category settings at start

overrideCategoryConfig applies config overrides when the shards start. Overrides are scoped and merged in this order (later wins):

  1. The category's own FNLB configuration.
  2. all — applies to every bot.
  3. categories — entries matching the bot's category.
  4. bots — entries matching the bot's id.
import FNLB from 'fnlb';
import { CategoryConfigPartyPrivacy } from '@fnlb-project/shared/types';

const fnlb = new FNLB();

await fnlb.start({
  apiToken: 'your-api-token',
  categories: ['category-id-1'],
  overrideCategoryConfig: {
    all: { acceptFriendRequests: false },
    categories: {
      'category-id-1': { privacy: CategoryConfigPartyPrivacy.Private }
    },
    bots: {
      'bot-id-1': { statusText: ['Special bot'] }
    }
  }
});

Overrides stay applied even if the category config is changed in the dashboard while the bots are running. Every key is in the category config reference.

Update your selection without restarting

After start(), you can change which categories or bots the running shards may use without calling stop().

MethodDescription
addCategories(ids, overrides?)Add category ids to the include list.
addBots(ids, overrides?)Add bot ids to the include list.
setCategories(ids?)Replace the category include list. Call with no arguments to make it unrestricted.
setBots(ids?, overrides?)Replace the bot include list. Call with no arguments to make it unrestricted.
removeCategories(ids)Remove category ids from the include list.
removeBots(ids)Remove bot ids from the include list.
getCategories()Current category include list (undefined means unrestricted).
getBots()Current bot include list (undefined means unrestricted).

The optional overrides argument is a partial category config applied to the ids you pass, using the same merge rules as overrideCategoryConfig. The keys are listed in category config.

import FNLB from 'fnlb';

const fnlb = new FNLB();

await fnlb.start({
  apiToken: 'your-api-token',
  categories: ['category-id-1'],
  botsPerShard: 10
});

// Add a category with a per-category override.
fnlb.addCategories(['category-id-2'], { acceptFriendRequests: false });

// Add a specific bot with its own override.
fnlb.addBots(['bot-id-1'], { acceptFriendRequests: false });

// Replace the selection entirely.
fnlb.setBots(['bot-id-1', 'bot-id-2']);
fnlb.setCategories(); // back to unrestricted

// Shrink the selection again.
fnlb.removeCategories(['category-id-1']);
fnlb.removeBots(['bot-id-1']);

Behavior details:

  • undefined means unrestricted for that dimension.
  • add* on an unrestricted dimension starts an include list (it narrows from "all").
  • add* on an existing list unions and de-duplicates.
  • set* replaces the list; passing undefined or omitting the argument makes it unrestricted.
  • remove* on an unrestricted dimension is a no-op.
  • Removing until the list is empty returns that dimension to unrestricted.
  • Overrides passed to add* or set* are stored per id and removed with remove* (or when set* drops that id).
  • These methods throw if no shards are running.

Stopping bots

await fnlb.stop();

This stops every shard and every bot managed by this instance.

Graceful shutdown

Stop the shards before the process exits so bots disconnect cleanly.

const shutdown = async () => {
  await fnlb.stop();
  process.exit(0);
};

process.on('SIGINT', shutdown);
process.on('SIGTERM', shutdown);

Naming your cluster

const fnlb = new FNLB({ clusterName: 'MyAwesomeCluster' });

await fnlb.start({ apiToken: 'your-api-token' });

The cluster name appears in logs and on the gateway.

Auto-restart every hour

Restarting periodically picks up SDK updates and clears long-lived connections.

async function startFNLB() {
  await fnlb.start({
    apiToken: 'your-api-token',
    categories: ['your-category-id'],
    numberOfShards: 1,
    botsPerShard: 5
  });
}

async function restartFNLB() {
  await fnlb.stop();
  await startFNLB();
}

await startFNLB();
setInterval(restartFNLB, 3_600_000);

Events, bots, and party meta

The SDK guides walk through this in full. After start(), the client emits events from the local shards and can call the bots they are running.

import FNLB, { Events } from 'fnlb';

const fnlb = new FNLB();

fnlb.on(Events.Ready, (bot) => {
  console.log(bot.displayName);
});

fnlb.on(Events.PartyMemberMessage, async (message) => {
  if (message.content === '!ping') await message.reply('pong');
});

await fnlb.start({
  token: 'your-api-token',
  categories: ['your-category-id']
});

const bot = await fnlb.bots.fetch('bot-id');
await bot.party.meta.get();
await bot.party.meta.set('Default:CustomMatchKey_s', 'my-key');
await bot.runCommand('outfit', ['renegade']);

fnlb.bots.cache is the bots running in this process. bot.party.me.meta reads and writes that bot's member meta. bot.friends(), bot.whisper(), party.invite, party.kick, party.promote, party.leave, and fnlb.fetchShardInfo() use the same local bridge.

HTTP API

See HTTP client for routes, scopes, and when to use the API instead of local IPC. fnlb.api calls https://api.fnlb.net/v1 with the start() token. Override the origin with apiBaseUrl.

const bots = await fnlb.api.bots.list();
const user = await fnlb.api.user.get();
await fnlb.api.bots.commands.run(bots[0].id, { command: 'emote', args: ['wave'] });
await fnlb.api.categories.list();
await fnlb.api.presets.list();

Cloud commands.run works for bots that are not running in this process. Local bot.runCommand talks to the shard directly.

Handling errors

try {
  await fnlb.start({ apiToken: 'your-api-token', categories: ['your-category-id'] });
} catch (error) {
  console.error('Failed to start FNLB:', error);
  process.exit(1);
}

Verifying your cluster

Check the shards the gateway currently knows about with GET /shards. If nothing appears, confirm that your token has the required scopes and that the machine can reach api.fnlb.net and gateway.fnlb.net.

From this portal

  • Join Discord

    Get help, support, or chat with other developers