The previous implementation of the RakNet ping was monolithic, mixing socket management, raw packet validation, and data transformation into a single, complex flow. This refactor introduces a clear, multi-stage processing pipeline that separates these concerns. The logic is now broken down into multi-stage pipeline: extracting the MOTD string from the raw pong packet -> parsing that string into a raw object -> transforming the raw data into a user-friendly response object. Additionally, the socket handling logic is improved with idempotent cleanup function to prevent resource leaks or race conditions. As part of this overhaul, external TypeScript definition (`.d.ts`) files have been removed in favor of rich JSDoc annotations. BREAKING CHANGE: The structure of the resolved `BedrockPingResponse` object has been significantly changed to improve clarity and consistency.
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
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: