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
The main Moonlink Manager instance that initialized this NodeManager.
A Map containing all registered nodes, keyed by their identifier.
State & Stats
Nodes with active WebSocket connections (may not be fully ready).
Nodes fully connected, authenticated, and ready for requests.
True if at least one node is connected.
True if at least one node is ready for playback.
The optimal node based on current load balancing.
Aggregated statistics for all online nodes.
Methods
init()
Initializes the NodeManager, adding all nodes from the configuration and initiating connections.
Note: This is called automatically by manager.init().
add(config)
add(config)#
→voidAdds a new Lavalink node to the manager and attempts to connect immediately.
The configuration object for the new node.
remove(identifier)
remove(identifier)#
→booleanDisconnects and removes a node from the manager. Returns true if successful.
The unique identifier of the node to remove.
findNode(options)
findNode(options)#
→Node | undefinedFinds 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.
Optional filters.
options
Array of node identifiers to ignore during selection.
eject(identifier)
eject(identifier)#
→Promise<boolean>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.
The identifier of the node to eject.