Timofey Gelazoniya c7b99cb6db
feat: implement SRV record lookup and improve ping logic
Add support for DNS SRV record lookups (`_minecraft._tcp`) to
automatically resolve the correct server host and port, falling back
to the provided address if no record is found. This makes server
discovery compliant with standard Minecraft client behavior.

The Java ping implementation has been refactored:
- The `varint` module is rewritten to throw specific error codes and
  its `decodeVarInt` function now returns bytes read, which simplifies
  parsing logic.
- The core ping logic is now promise-based and modular, breaking out
  packet creation and response processing into helper functions.
- The TCP stream handler now robustly processes chunked data by
  catching recoverable decoder errors and waiting for more data,
  preventing crashes on incomplete packets.
- Error handling is improved.
2025-06-19 01:45:27 +03:00
2022-01-10 23:21:47 +03:00
2022-01-10 23:21:47 +03:00
2022-01-10 23:21:47 +03:00

mineping

This JavaScript library provides an implementation of the Minecraft server ping protocol. It allows you to gather information about a Minecraft server, such as the MOTD, current online players, server icon (Java Edition only), and more.

Mirror on my Git

Requirements

Node.js 14 or newer is required

Install

To install mineping, simply run the following command:

npm i @minescope/mineping

To install beta version (if available), run: npm i @minescope/mineping@next

Loading and configuration the module

ES Modules (ESM)

If you are using ES Modules, you can import the library like this:

import { pingJava, pingBedrock } from "@minescope/mineping";

CommonJS

mineping is an ESM-only module — you are not able to import it with require(). If you cannot switch to ESM, you can use the async import() function from CommonJS to load mineping asynchronously:

const pingJava = (...args) =>
	import("@minescope/mineping").then((module) => module.pingJava(...args));
const pingBedrock = (...args) =>
	import("@minescope/mineping").then((module) => module.pingBedrock(...args));

Usage

Ping a Java server with default options:

import { pingJava } from "@minescope/mineping";

const data = await pingJava("mc.hypixel.net");
console.log(data);

Ping a Bedrock server with custom options:

import { pingBedrock } from "@minescope/mineping";

const data = await pingBedrock("mco.mineplex.com", {
	port: 19132,
	timeout: 500,
});
console.log(data);

More complex example can be found in the example folder!

Acknowledgements

Special thanks to the following projects:

  • mcping crate for Rust
  • mcping-js library for quering Minecraft Java Edition servers
Description
Ping both Minecraft Bedrock and Java servers.
Readme MIT 243 KiB
Languages
JavaScript 100%