Skip to main content
The Deno 2 Release Candidate is here
Learn more

Minecraft CurseForge API

An ergonomic Deno wrapper around the NPM package curseforge-api, tailored just for Minecraft.

Table of Contents

Getting Started

In a Deno project:

import { CurseForge } from "https://deno.land/x/minecraft_curseforge_api@0.4.0/mod.ts";

const curseForge = new CurseForge("YOUR_API_KEY");

await curseForge.getMod(slugOrID);
await curseForge.searchMods(nameOrAuthor, options);
await curseForge.getFiles(modID, options);
await curseForge.getNewestFile(modID, options);

const dependencies = curseForge
  .dependencies({ file, minecraftVersion, modLoader, ...options });

for await (const dependency of curseForge.dependencies({ file, ...options })) {
  // do something with dependency
}

// helper methods
await dependencies.toEntries();
await dependencies.toObject();
await dependencies.toFiles();
await dependencies.toMap();
await dependencies.toGraph();

Type Definitions

The package provides robust types specific to Minecraft, trimming out unused or irrelevant CurseForge fields, and altering the raw data to be more user-friendly and human-readable.

import type {
  File,
  MinecraftVersion,
  Mod,
  ModLoader,
} from "https://deno.land/x/minecraft_curseforge_api@0.4.0/mod.ts";

Types are also re-exported under the CurseForge namespace, which is merged with the main CurseForge class. This allows you to keep your imports very clean, and in more complex files it contextualizes type names for ease of comprehension.

import { CurseForge } from "https://deno.land/x/minecraft_curseforge_api@0.4.0/mod.ts";

const curseForge = new CurseForge("YOUR_API_KEY");

const modLoader: CurseForge.ModLoader = "Forge"; // easy access

let file: CurseForge.File; // disambiguated from browser File API or other File types

Cache

API calls are cached in-memory to avoid duplicate lookups.

await curseForge.getMod("jei");
await curseForge.getMod("jei"); // cached; doesn't make a network request

The cache is cleared when the CurseForge instance is garbage collected, or when the clearCache() method is called.

curseForge.clearCache();

Complete Example

In this example, we get the popular mod Quark, find its newest file for our targeted Minecraft version and mod loader, then fetch all of its required dependencies. At each stage we check to ensure that the previous operation was successful before proceeding - in this exact example it’s not necessary, but if you copy this script and modify the mod slug, mod loader, or minecraft version, these checks will save you!

import { CurseForge } from "https://deno.land/x/minecraft_curseforge_api@0.4.0/mod.ts";

const curseForge = new CurseForge("YOUR_API_KEY");
const modLoader: CurseForge.ModLoader = "Forge";
const minecraftVersion: CurseForge.MinecraftVersion = "1.19.2";

const mod = await curseForge.getMod("quark");

if (!mod) {
  console.log("Couldn't find a mod with that slug!");
  Deno.exit(1);
}

const file = await curseForge
  .getNewestFile(mod.id, { minecraftVersion, modLoader });

if (!file) {
  console.log("Couldn't find a file for this mod loader and MC version!");
  Deno.exit(1);
}

curseForge
  .dependencies({ file, minecraftVersion, modLoader, include: ["required"] })
  .toFiles()
  .then((depFiles) =>
    depFiles.forEach((depFile) => console.log(depFile.displayName))
  );