2022-01-10 20:21:47 +00:00
# mineping
2023-10-22 19:49:53 +00:00
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.
2022-01-10 20:21:47 +00:00
2022-08-23 13:22:42 +00:00
Mirror on my [<img src="https://git.zeldon.ru/assets/img/logo.svg" align="center" width="20" height="20"/> Git ](https://git.zeldon.ru/zeldon/mineping )
2022-01-10 20:21:47 +00:00
## Requirements
2022-08-23 13:22:42 +00:00
2022-01-10 20:21:47 +00:00
> **[Node.js](https://nodejs.org/) 14 or newer is required**
2022-01-10 20:30:56 +00:00
## Install
2023-10-22 19:49:53 +00:00
To install `mineping` , simply run the following command:
2022-01-10 20:30:56 +00:00
```
npm i @minescope/mineping
```
2022-01-10 23:24:39 +00:00
## Loading and configuration the module
### ES Modules (ESM)
2023-10-22 19:49:53 +00:00
If you are using ES Modules, you can import the library like this:
2022-01-10 23:24:39 +00:00
```js
2022-01-10 23:33:30 +00:00
import { pingJava, pingBedrock } from '@minescope/mineping';
2022-01-10 23:24:39 +00:00
```
### CommonJS
2022-08-23 13:22:42 +00:00
2022-01-10 23:33:30 +00:00
`mineping` is an ESM-only module — you are not able to import it with `require()` .
2022-01-10 23:24:39 +00:00
If you cannot switch to ESM, you can use the async `import()` function from CommonJS to load `mineping` asynchronously:
```js
2022-01-10 23:33:30 +00:00
const pingJava = (...args) => import('@minescope/mineping').then(module => module.pingJava(...args));
const pingBedrock = (...args) => import('@minescope/mineping').then(module => module.pingBedrock(...args));
2022-01-10 23:24:39 +00:00
```
## Usage
2022-01-10 20:21:47 +00:00
Ping a Java server with default options:
```js
2022-01-10 23:33:30 +00:00
import { pingJava } from '@minescope/mineping';
2022-01-10 20:21:47 +00:00
const data = await pingJava('mc.hypixel.net');
console.log(data);
```
Ping a Bedrock server with custom options:
```js
2022-01-10 23:33:30 +00:00
import { pingBedrock } from '@minescope/mineping';
2022-01-10 20:21:47 +00:00
const data = await pingBedrock('mco.mineplex.com', {
port: 19132,
timeout: 500
2022-01-10 22:11:18 +00:00
});
2022-01-10 22:09:13 +00:00
console.log(data);
2022-01-10 20:21:47 +00:00
```
2022-08-23 13:22:42 +00:00
2022-01-10 20:37:07 +00:00
> More complex example can be found in the `example` folder!
2022-01-10 20:21:47 +00:00
## Acknowledgements
2022-08-23 13:22:42 +00:00
2023-10-22 19:49:53 +00:00
Special thanks to the following projects:
2022-01-10 20:21:47 +00:00
- [mcping ](https://github.com/Scetch/mcping ) crate for Rust
2022-08-23 13:22:42 +00:00
- [mcping-js ](https://github.com/Cryptkeeper/mcping-js ) library for quering Minecraft Java Edition servers