An implementation of modrinth API (https://docs.modrinth.com/api-spec)
npm install @xmcl/modrinth




Provide the modrinth described in https://docs.modrinth.com/api-spec
This package is depending on undici for HTTP in nodejs, and the browser version will use browser fetch instead of undici.
You can use keyword to search
``ts${project.project_id} ${project.title} ${project.description}
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(); // print project info`
}
You can get project detail info via project id, including the download url
`ts
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
``