Registry / http-networking / musicbrainz-api

musicbrainz-api

JSON →
library1.2.0jsnpmunverified

The `musicbrainz-api` package provides a TypeScript-first client for interacting with the MusicBrainz web service, enabling both reading detailed metadata and submitting new information to the database. Currently at stable version 1.2.0, the library maintains an active release cadence with updates typically occurring every few weeks or months. Key differentiators include its robust support for retrieving various entity types, comprehensive TypeScript definitions for enhanced developer experience, and intelligent request throttling that automatically adheres to MusicBrainz API rate limits, including retries for rate-limit hits. It simplifies the required application identification (User-Agent) by prompting for `appName`, `appVersion`, and `appContactInfo` during client configuration. This library exclusively uses ECMAScript Modules (ESM) since version 8, requiring Node.js 16 or higher for usage.

npm install musicbrainz-api
INSTALL
IMPORT
SIG · MUSICBRAINZ-API
M
musicbrainz-api
http-networkingjavascriptv1.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MusicBrainzApi
import { MusicBrainzApi } from 'musicbrainz-api'
const MusicBrainzApi = require('musicbrainz-api')
The library is pure ECMAScript Module (ESM) since v8. CommonJS `require()` is not supported.
Artist
import type { Artist } from 'musicbrainz-api'
import { Artist } from 'musicbrainz-api'
When importing types for type annotations in TypeScript, use `import type` to ensure they are stripped from the JavaScript output.
ReleaseIncludes
import type { ReleaseIncludes } from 'musicbrainz-api'
Used to specify included relations when fetching data, enabling more comprehensive responses from the API.

Initializes the MusicBrainz API client and performs a search for an artist, logging basic details.

import { MusicBrainzApi } from 'musicbrainz-api'; import type { Artist } from 'musicbrainz-api'; const client = new MusicBrainzApi({ appName: 'MyAwesomeApp', appVersion: '1.0.0', appContactInfo: 'mailto:me@example.com' // Required by MusicBrainz API }); async function searchArtist(query: string) { try { console.log(`Searching for artist: ${query}...`); const result = await client.searchArtist(query); if (result.artists && result.artists.length > 0) { const firstArtist: Artist = result.artists[0]; console.log(`Found artist: ${firstArtist.name} (MBID: ${firstArtist.id})`); if (firstArtist.area) { console.log(` Area: ${firstArtist.area.name}`); } if (firstArtist['life-span']) { console.log(` Life Span: ${firstArtist['life-span'].begin || 'Unknown'} - ${firstArtist['life-span'].end || 'Present'}`); } } else { console.log('No artists found.'); } } catch (error) { console.error('Error searching for artist:', error); } } searchArtist('Radiohead'); searchArtist('Pink Floyd');
Debug
Known issues
breakingStarting from version 8.0.0, `musicbrainz-api` is a pure ECMAScript Module (ESM) and no longer supports CommonJS `require()`. This also elevates the minimum required Node.js version to 16 or higher.
fix
Migrate your project to ESM by adding `"type": "module"` to your `package.json` and updating `require()` calls to `import` statements. Ensure your Node.js version is 16 or newer.
affects: >=8.0.0
gotchaMusicBrainz API clients are required to identify their application via the User-Agent header. Failure to provide `appName`, `appVersion`, and `appContactInfo` when initializing `MusicBrainzApi` will result in HTTP 400 Bad Request errors.
fix
Always initialize the client with `new MusicBrainzApi({ appName: 'YourAppName', appVersion: 'X.Y.Z', appContactInfo: 'you@example.com' })`.
affects: >=0.1.0
breakingError reporting for `400 Bad Request` responses was improved in `v1.1.0`. Code relying on specific error message formats or structures for 400-level errors in older versions may behave differently.
fix
Review error handling logic, especially for 400 Bad Request responses, and adapt to potentially more detailed or structured error objects. Implement robust error parsing to avoid future breaking changes.
affects: >=1.1.0
gotchaWhile the library implements intelligent throttling and retries on rate limit hits, excessive or misconfigured requests can still lead to temporary IP bans or persistent `429 Too Many Requests` errors from the MusicBrainz server. Ensure `appContactInfo` is valid for communication.
fix
Ensure your application adheres to reasonable request patterns. For heavy usage, consider distributing requests over time or reaching out to MusicBrainz for specific permissions if necessary. Provide accurate `appContactInfo`.
affects: >=0.25.1
breakingPrior to version 0.24.0, the `browse` function was more restrictive, only allowing a single MusicBrainz ID (MBID) per entity. Version 0.24.0 introduced new overloads allowing more flexible usage with optional `inc` parameters.
fix
If migrating from older versions, update calls to `browse` to utilize the new overloads, which may require adjusting how entity IDs and include parameters are passed. For new development, prefer the most flexible `browse` signatures.
affects: <0.24.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Attempting to use `require()` to import the `musicbrainz-api` package in a CommonJS module, but the library is pure ESM.
fix
Change your import statement to `import { MusicBrainzApi } from 'musicbrainz-api';` and ensure your project is configured for ESM (e.g., `"type": "module"` in `package.json`).
Error searching for artist: MusicBrainzApiError: Bad Request (status: 400)
The MusicBrainz API requires a User-Agent header, which is constructed from `appName`, `appVersion`, and `appContactInfo`. This error indicates one of these was likely missing or invalid.
fix
When initializing `MusicBrainzApi`, ensure all three fields (`appName`, `appVersion`, `appContactInfo`) are provided and valid, e.g., `new MusicBrainzApi({ appName: 'MyApp', appVersion: '1.0.0', appContactInfo: 'me@example.com' })`.
UnhandledPromiseRejectionWarning: MusicBrainzApiError: Too Many Requests (status: 429)
Your application has sent too many requests in a short period, exceeding MusicBrainz's rate limits.
fix
Review your application's request frequency. While the library implements retries, sustained high volume can still trigger this. Ensure `appContactInfo` is valid. Consider spacing out requests or implementing custom back-off strategies if necessary.
Cannot find name 'Artist'.
In TypeScript, the `Artist` type was imported using a regular `import` statement instead of `import type`, or the import path was incorrect.
fix
For type-only imports, use `import type { Artist } from 'musicbrainz-api';`. If `Artist` is used as a value, ensure it's exported as such (though typically it's only a type).
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources