minestat
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

MineStat

MineStat is a Minecraft server status checker.

Exposes two methods:

ìnit

  • Fetches the server status asynchronously, with an optional timeout
init(address: string, port: number): Promise<Stats>;
init(address: string, port: number, timeout: number): Promise<Stats>;

ìnitSync

  • Synchronously fetches the server status, using a callback, with an optional timeout
initSync(address: string, port: number, callback: (error?: Error, result: Stats) => void): void;
init(address: string, port: number, timeout: number, callback: (error?: Error, result: Stats) => void): void;

Returns a Stats object. For offline server statuses:

{
  address: string; // The original address you provided
  port: number; // The original port you provided
  latency: number; // Ping to server in ms
  offline: false;
}

For online servers:

{
  address: string;
  port: number;
  latency: number;
  online: true;
  version: string;
  max_players: number;
  current_players: number;
  motd: string; // Message of the day
}

JavaScript async example

const ms = require('minestat');
(async () => {
  try
  {
    const result = await ms.init({address: 'minecraft.frag.land', port: 25565});
    console.log("Minecraft server status of " + result.address + " on port " + result.port + ":");
    if(result.online)
    {
      console.log("Server is online running version " + result.version + " with " + result.current_players + " out of " + result.max_players + " players.");
      console.log("Message of the day: " + result.motd);
      console.log("Latency: " + result.latency + "ms");
    }
    else
    {
      console.log("Server is offline!");
    }
  }
  catch(error)
  {
    throw error;
  }
})();

JavaScript synchronous example

var ms = require('minestat');
ms.initSync({address: 'minecraft.frag.land', port: 25565}, function(result)
{
  console.log("Minecraft server status of " + result.address + " on port " + result.port + ":");
  if(result.online)
  {
    console.log("Server is online running version " + result.version + " with " + result.current_players + " out of " + result.max_players + " players.");
    console.log("Message of the day: " + result.motd);
    console.log("Latency: " + result.latency + "ms");
  }
  else
  {
    console.log("Server is offline!");
  }
});

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.0.0
    0
    • latest

Version History

Package Sidebar

Install

npm i minestat

Weekly Downloads

1

Version

2.0.0

License

GPL-3.0

Unpacked Size

10.2 kB

Total Files

8

Last publish

Collaborators

  • ldilley