@xmcl/modrinth
TypeScript icon, indicating that this package has built-in type declarations

2.3.1 • Public • Published

Modrinth API

npm version Downloads Install size npm Build Status

Provide the modrinth described in https://docs.modrinth.com/api-spec

Usage

This package is depending on undici for HTTP in nodejs, and the browser version will use browser fetch instead of undici.

Search Project in Modrinth

You can use keyword to search

import { ModrinthV2Client, SearchResult } from '@xmcl/modrinth'
const client = new ModrinthV2Client()
const searchOptions: SearchOptions = {
    query: "shader", // searching shader
};
const result: SearchResult = await client.searchProjects(settingString);
const totalProjectCounts = result.total_hits;
for (const project of result.hits) {
    console.log(`${project.project_id} ${project.title} ${project.description}`); // print project info
}

Get Project in Modrinth

You can get project detail info via project id, including the download url

import { ModrinthV2Client, ProjectVersionFile, ProjectVersion } from '@xmcl/modrinth'

const client = new ModrinthV2Client()
const projectId: string; // you can get this id from searchProjects
const project: project = await client.getProject(projectId) // project details
const versions: string[] = project.versions;
const oneVersion: string = versions[0];

const modVersion: ModVersion = await getProjectVersion(oneVersion);

const files: ProjectVersionFile[] = modVersion.files;

const { url, name, hashes } = files[0]; // now you can get file name, file hashes and download url of the file

Dependents (1)

Package Sidebar

Install

npm i @xmcl/modrinth

Weekly Downloads

48

Version

2.3.1

License

MIT

Unpacked Size

169 kB

Total Files

17

Last publish

Collaborators

  • ci010