Steam Master and Game Server Query

1.1.3 · active · verified Tue Apr 21

This package provides a promise-based Node.js module for programmatically interacting with Steam's Master Server Query Protocol and Game Server Queries. It enables developers to fetch lists of active game servers from a Steam master server, supporting extensive filtering by region and various server properties (e.g., game directory, map, player count, appid). Additionally, it fully supports querying individual game servers for detailed information via A2S_INFO (server name, map, players), A2S_PLAYER (player list with scores and duration), and A2S_RULES (server-specific rules and values). The current stable version is 1.1.3, with recent releases focusing on improved socket stability, enhanced retry mechanisms for queries, and options to mitigate rate limiting during master server lookups. It ships with comprehensive TypeScript type definitions, ensuring robust usage in modern JavaScript and TypeScript environments. Its primary differentiator is its complete implementation of both Master and Game Server Query protocols with a resilient, promise-based API.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates querying a Steam master server to find Team Fortress 2 servers, then querying the first found game server for its detailed information and player list.

import { queryMasterServer, queryGameServerInfo, queryGameServerPlayer, REGIONS } from 'steam-server-query';

async function runQuery() {
  try {
    console.log('Querying master server for all regions...');
    const masterServers = [
      'hl2master.steampowered.com:27011',
      'hl2master.steampowered.com:27012'
    ];

    const gameServers = await queryMasterServer(masterServers[0], REGIONS.ALL, {
      appid: 440, // Team Fortress 2
      gamedir: 'tf',
      empty: 1
    }, 2000, 5); // Timeout 2s, max 5 hosts

    if (gameServers.length === 0) {
      console.log('No game servers found matching criteria.');
      return;
    }

    console.log(`Found ${gameServers.length} game servers. Querying the first one: ${gameServers[0]}`);

    const serverInfo = await queryGameServerInfo(gameServers[0]);
    console.log('\n--- Server Info ---');
    console.log(`Name: ${serverInfo.name}`);
    console.log(`Map: ${serverInfo.map}`);
    console.log(`Players: ${serverInfo.players}/${serverInfo.maxPlayers}`);
    console.log(`Game: ${serverInfo.game}`);

    const playerInfo = await queryGameServerPlayer(gameServers[0]);
    console.log('\n--- Player Info ---');
    playerInfo.players.forEach(player => {
      console.log(`- ${player.name} (Score: ${player.score}, Duration: ${player.duration.toFixed(2)}s)`);
    });

    // Example of handling potential errors or missing player data
    if (playerInfo.players.length === 0) {
      console.log('No players found on this server.');
    }

  } catch (error) {
    console.error('An error occurred during the query:', error.message);
    if (error.code === 'ETIMEDOUT') {
      console.error('The server query timed out. The server might be offline or unreachable.');
    }
  }
}

runQuery();

view raw JSON →