npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@leventhan/battlemetrics

v2.0.0

Published

An object-oriented BattleMetrics (API) package for NodeJS. With error handling and control checks before sending API requests.

Readme

BattleMetrics

A zero-dependency Node.js client for the BattleMetrics API.

This package provides resource-based methods for the documented BattleMetrics JSON:API endpoints, plus compatibility methods for projects that used the older BattleMetricsAPI-style wrapper.

Installation

npm install @leventhan/battlemetrics
const BM = require("@leventhan/battlemetrics");

Quick Start

Create a BattleMetrics API token from your BattleMetrics developer settings, then pass the token without the Bearer prefix.

const BM = require("@leventhan/battlemetrics");

const battleMetrics = new BM({
  token: process.env.BM_TOKEN,
});

const server = await battleMetrics.servers.info("10281405");

console.log(server.data.attributes.name);

Resource API

Resource methods return the raw BattleMetrics JSON:API response document.

const servers = await battleMetrics.servers.list({
  filter: {
    search: "squad",
    game: "squad",
  },
  page: {
    size: 10,
  },
});

Query helpers support BattleMetrics JSON:API options such as filter, page, fields, include, and sort.

const server = await battleMetrics.servers.info("10281405", {
  include: "player",
  fields: {
    server: "name,ip,port",
  },
});

POST and PATCH endpoints accept a JSON:API request body as the first argument after path parameters.

const matches = await battleMetrics.players.matchIdentifiers(
  BM.createIdentifierDocument("steamID", "76561198110941835"),
);

Every namespace also includes a low-level request method for new or changed BattleMetrics endpoints.

const result = await battleMetrics.servers.request("GET", "/servers", {
  query: {
    filter: { search: "rust" },
    page: { size: 5 },
  },
});

Namespaces

The client currently includes these namespaces:

bans, banLists, banListExemptions, banListInvites, nativeBans, commandsActivity, coplay, dataPoints, files, games, gameFeatures, players, playerIdentifiers, playerFlags, playerNotes, relatedPlayerQueries, playerQueryResults, reservedSlots, servers, serverGroups, sessions, organizations, organizationFriends, stats, and users.

For the full endpoint matrix, see docs/API-COVERAGE.md.

Compatibility Methods

Older method names are still available for migration purposes. They emit a deprecation warning once per method per client instance.

const server = await battleMetrics.getServerInfoById("10281405");

Prefer the resource API for new code:

const server = await battleMetrics.servers.info("10281405");

Available compatibility methods:

  • getServerInfoById(serverId)
  • getGameInfo(game)
  • getServerInfoByName(name, pageLength)
  • getServerInfoByNameAndGame(serverName, game, pageLength)
  • getAllServersByServerNameCountryAndGame(serverName, country, game, pageLength)
  • getPlayTimeHistory(playerId, serverId, startTime, stopTime)
  • getServerPlayerInfo(playerId, serverId)
  • getPlayerInfo(playerId)
  • getBanInfoByID(banId)
  • getBans(query)
  • getLeaderBoard(listSize, startTime, stopTime)
  • getGameFeatures(game)
  • getGameFeatureOptionsList(gameFeatureId)
  • getPlayerInfoBy(typeIdentifier, identifier)
  • getPlayersInfoBy(typeIdentifier, identifiers)

To silence compatibility warnings:

const battleMetrics = new BM({
  token: process.env.BM_TOKEN,
  deprecationWarnings: false,
});

Debugging

Enable debug mode to log each response payload with method, URL, query params, status, and failure state. Request headers are not logged, so your API token is not printed.

const battleMetrics = new BM({
  token: process.env.BM_TOKEN,
  debug: true,
});

You can also enable debug logging with BM_DEBUG=true.

Use debugLogger to route logs into your own logger.

const battleMetrics = new BM({
  token: process.env.BM_TOKEN,
  debug: true,
  debugLogger: (label, payload) => logger.debug(label, payload),
});

Constructor Options

const battleMetrics = new BM({
  token: process.env.BM_TOKEN,
  serverID: "10281405",
  game: "squad",
  timeout: 10000,
  debug: false,
  deprecationWarnings: true,
});
  • token: BattleMetrics API token, without Bearer.
  • serverID: Optional default server ID used by compatibility helpers.
  • game: Optional default game ID used by compatibility helpers.
  • timeout: Optional request timeout in milliseconds.
  • debug: Enables response logging.
  • debugLogger: Custom debug logging function.
  • deprecationWarnings: Set to false to silence compatibility warnings.
  • baseURL: Override the API base URL for testing.
  • httpClient: Inject a request-compatible client for tests.

Errors

Failed API responses are normalized into BM.BattleMetricsError.

try {
  await battleMetrics.bans.list();
} catch (error) {
  if (error.isBattleMetricsError) {
    console.error(error.status, error.detail);
  }
}

The original BattleMetrics JSON:API errors array is available as error.errors.

Tests

npm test

Additional scripts:

npm run test:unit
npm run test:contract
npm run test:live:read
npm run test:live:mutation

Local live test scripts automatically read .env with Node's built-in --env-file-if-exists flag. Normal npm test does not require .env.

Live mutation tests are intentionally gated because they can create, update, or delete BattleMetrics resources.

BM_ENABLE_MUTATION_TESTS=true
BM_CONFIRM_MUTATION_TESTS=I_UNDERSTAND_THIS_MUTATES_BATTLEMETRICS

Required live test variables:

  • BM_TOKEN
  • BM_TEST_GAME
  • BM_TEST_SERVER_ID
  • BM_TEST_PLAYER_ID
  • BM_TEST_IDENTIFIER_TYPE
  • BM_TEST_IDENTIFIER

Optional admin and mutation fixture variables are listed in .env.example and docs/API-COVERAGE.md.