npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@musikbotapp/lastfm-client

v1.1.0

Published

Zero-dependency TypeScript client for the Last.fm API with normalized responses and rate limiting.

Downloads

45

Readme

lastfm-client

Zero-dependency TypeScript client for the Last.fm API with normalized responses and rate limiting.

Quick Start

1. Installation

npm install @musikbotapp/lastfm-client

2. Initialization

Using Environment Variables

If LASTFM_API_KEY, LASTFM_API_SECRET, and LASTFM_API_USER_AGENT are set in your environment, initialization is zero-config:

import { LastFm } from "@musikbotapp/lastfm-client";

const fm = new LastFm();

Using Custom Settings

Alternatively, you can pass explicit configuration options:

import { LastFm } from "@musikbotapp/lastfm-client";

const fm = new LastFm({
  api: {
    key: "YOUR_KEY",
    secret: "YOUR_SECRET",
    userAgent: "YourApp/1.0.0 ([email protected])",
  },
  rateLimit: {
    bucketMax: 3,
    refillIntervalMs: 300,
    maxQueueSize: 200,
    backOffBaseMs: 5_000,
    backOffOutageBaseMs: 10_000,
  },
  network: {
    retries: 1,
    abortTimeoutMs: 4_000,
    retryStrategy: {
      onRateLimit: true,
      onServiceOutage: true,
      onTimeout: true,
    },
  },
  behavior: {
    autoCorrectByDefault: true,
    emitRequestFailedOnReject: true,
  },
});

Usage Examples

All methods return fully typed, parsed, and normalized responses.

Fetching User Info

  • Get Loved Tracks
const res = await fm.user.getLovedTracks({ user: "username" });

if (!res.success) return console.warn(`(${res.errorCode}) ${res.errorMsg}`);

console.info(res.lovedTracks);
  • Get Now Playing Track
const res = await fm.user.getNowPlaying({ user: "username" });

if (!res.success) return console.warn(`User is currently offline.`);

console.info(`Listening to: ${res.track.name} by ${res.track.artist.name}`);

Scrobbling

  • Single Track
const res = await fm.track.scrobble({
  sk: "SESSION_KEY",
  track: "Aja",
  artist: "Steely Dan",
  timestamp: Math.floor(Date.now() / 1000),
  meta: { userId }, // optional
});

if (!res.success) return console.warn(`(${res.errorCode}) ${res.errorMsg}`);
  • Batch Scrobbling
const now = Math.floor(Date.now() / 1000);
const tracks = [
  { track: "Aja", artist: "Steely Dan", timestamp: now },
  { track: "Keith Don't Go", artist: "Nils Lofgren", timestamp: now - 120 },
];

const res = await fm.track.scrobbleBatch({
  sk: "SESSION_KEY",
  tracks,
  meta: { userId }, // optional
});

if (!res.success) {
  return console.warn(`(scrobbled: ${res.scrobbledCount}) (${res.errorCode}) ${res.errorMsg}`);
}

Event Handling

Listen to internal client events to monitor network behavior or handle session states.

// Failed requests
fm.on("requestFailed", (payload) => {
  const { apiMethod, attempt, message, queueSize, willRetry } = payload;
  console.warn(`[${apiMethod}]: (Attempt: ${attempt}, Retry: ${willRetry}) (queueSize: ${queueSize}) ${message}`);
});

// Expired sessions
fm.on("sessionExpire", (message, meta) => {
  console.info(`[sessionExpire]: ${message}`, meta);
});

// Warnings
fm.on("warn", (info) => {
  console.warn(`[${info.apiMethod}]: ${info.message}`);
});