Skip to content

JavaScript resources

JavaScript is the supported server runtime for the current Varion MVP. Node.js must be available on PATH. A separate js-module is not required: the server starts its Node host automatically when a resource with type = "js" is loaded.

toml
# server.toml (keep the array on one line)
resources = ["my-gamemode"]
toml
# resources/my-gamemode/resource.toml
enabled = true
type = "js"
main = "server/main.js"
client-type = "js"
client-main = "client/main.js"
client-files = ["client/**"]

Minimal server resource

js
varion.on('playerConnect', (player) => {
  varion.log(`connected ${player.id} ${player.name}`);
});

varion.on('playerReady', (player) => {
  player.spawn({ x: 215.76, y: -810.12, z: 30.73 }, 157, 0x705E61F2);
});

varion.onClient('chat:send', (player, text) => {
  varion.emitAllClients('chat:message', player.name, String(text));
});

varion.onRpc('profile:get', (player) => ({ id: player.id, name: player.name }));

playerConnect, playerReady, onClient, and onRpc receive a Player object, not a numeric playerId. To reply to a specific player use player.emit(...).

Ordinary Node builtins are available through require(...); npm dependencies are installed into the resource's own node_modules. The current full starter example is in sdk/templates/js-full-resource.

C# and Go are not loaded by the current server binary and are considered preview.

Varion Multiplayer Platform