Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

mojang-lib

Owen3H93MIT1.14.0TypeScript support: included

A modern wrapper for interacting with the Mojang API.

mojang, minecraft, minecraft-lib, mojang-api, typescript

readme

mojang-lib GitHub repo size npm bundle size

A modern wrapper for interacting with the Mojang API.

This library is a rewritten version of minecraft-lib in TypeScript.
The list of changes made are available here.

Read the docs

Install

Bun - bun add mojang-lib\ PNPM - pnpm add mojang-lib

Usage

ESM

import { players, servers } from "mojang-lib"

const server = await servers.get('play.earthmc.net')
console.log(server)

const player = await players.get('Owen3H')
console.log(player)

CommonJS

const MCAPI = require("mojang-lib")

async function runTest() {
  const server = await MCAPI.servers.get('play.earthmc.net')
  console.log(server)

  const player = await MCAPI.players.get('Owen3H')
  console.log(player)
}

runTest()

changelog

List of Changes (From original minecraft-lib)

⬜ General QoL

  • Removed big minecraft-data dependency and replaced js-base64 with built-in alternative.
  • MCAPI_MISC export removed as its features were deprecated.
  • Type declarations included for clarity and easier debugging.

⬜ Fixed vulnerabilities

  • Dependency request no longer used as it was unmaintained.
  • Fixed 12 high level issues via npm audit fix.

⬜ Improved perf/safety

  • Deprecated request dependency replaced with Undici for much better latency & throughput.
  • Reduced slow for in and for of loops with optimized alternatives.
  • Map now used over built-in object (where applicable).
  • All cases of var changed to its modern let or const counterpart.
  • Prevented unnecessary object creation in some areas.

⬜ ESM Syntax

  • Set package.json type to module.
  • Used import/export instead of require.
  • Promise chaining replaced with async/await.