Query Server
Example
import {
ServerPlatform,
getMinecraftServer,
type CachedBedrockMinecraftServer,
type CachedJavaMinecraftServer,
type RestfulMCAPIError,
} from "restfulmc-lib";
try {
const server: CachedJavaMinecraftServer | CachedBedrockMinecraftServer =
await getMinecraftServer(ServerPlatform.JAVA / ServerPlatform.BEDROCK, "hypixel.net");
console.log(
`Pinged ${server.ip}:${server.port}, there are ${server.players.online}/${server.players.max} players online`
);
} catch (err) {
if ((err as RestfulMCAPIError).code == 404) {
console.error("Server couldn't be found, is it offline?");
}
}
Output
$ bun index.ts
Pinged 209.222.115.114:25565, there are 39335/200000 players online