Star ✨ on GitHub

NodeManager

Manages all Lavalink node connections, including load balancing, automatic failover, and statistics monitoring.

The NodeManager handles the lifecycle of your Lavalink nodes. It is responsible for connecting to nodes, tracking their health (CPU/Memory usage), and selecting the best node for new players based on load balancing strategies.

Properties

NodeManager Properties

Core components and state accessible via the NodeManager instance.

References

managerManager

The main Moonlink Manager instance that initialized this NodeManager.

nodesMap<string, Node>

A Map containing all registered nodes, keyed by their identifier.

State & Stats

onlineNodesNode[]

Nodes with active WebSocket connections (may not be fully ready).

readyNode[]

Nodes fully connected, authenticated, and ready for requests.

hasOnlineNodesboolean

True if at least one node is connected.

hasReadyboolean

True if at least one node is ready for playback.

leastUsedNodeNode | undefined

The optimal node based on current load balancing.

statsRecord<string, any>

Aggregated statistics for all online nodes.

Methods

init()

init()#

Initializes the NodeManager, adding all nodes from the configuration and initiating connections. Note: This is called automatically by manager.init().

Example
// Usually called internally
manager.nodes.init();

add(config)

Adds a new Lavalink node to the manager and attempts to connect immediately.

configIManagerNodeConfig required

The configuration object for the new node.

Example
manager.nodes.add({
    host: "backup.lavalink.org",
    port: 2333,
    password: "youshallnotpass",
    identifier: "Node-01" // We will use this ID in other examples
});

remove(identifier)

Disconnects and removes a node from the manager. Returns true if successful.

identifierstring required

The unique identifier of the node to remove.

Example
const success = manager.nodes.remove("Node-01");
if (success) console.log("Node-01 removed successfully.");

findNode(options)

findNode(options)#

Finds the best available node based on the configured selectionStrategy (e.g., least load, lowest memory). It also respects health checks (CPU/Memory limits) if configured.

optionsobject

Optional filters.

options

excludestring[]

Array of node identifiers to ignore during selection.

Example
// Find a node but exclude "Node-01" explicitly
const node = manager.nodes.findNode({
    exclude: ["Node-01"]
});

eject(identifier)

eject(identifier)#

Gracefully removes a node. Unlike remove(), this method first attempts to move all active players from this node to another healthy node. If no other nodes are available, the players are destroyed.

identifierstring required

The identifier of the node to eject.

Example
// Move players off "Node-01" and shut it down
await manager.nodes.eject("Node-01");
console.log("Node-01 ejected safely.");