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

@arxyf/fm

v1.2.0

Published

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

Readme

@arxyf/fm

npm version Language License: MIT

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

📖 API Reference

Key Features

  • Zero-Dependency Core: Fully typed TypeScript client for the Last.fm API with no external runtime dependencies.

  • Normalized Responses: Every method returns parsed, consistently shaped, fully typed responses instead of raw API payloads.

  • Built-In Rate Limiting: Configurable token-bucket limiter with queueing and backoff for both rate-limit and service-outage scenarios.

  • Resilient Networking: Automatic retries with configurable strategies for timeouts, rate limits, and outages, backed by request abort timeouts.

  • Batch Scrobbling: Scrobble single tracks or submit batches in one call, with per-batch success counts on partial failure.

  • Event-Driven Monitoring: Emits events for failed requests and expired sessions so you can hook in your own logging or alerting.

Requirements

  • Node.js: ≥ 18.0.0
  • Last.fm API Key & Secret

Installation

npm install @arxyf/fm

Quickstart

Initialization (Environment Variables)

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

import { FMClient } from "@arxyf/fm";

const fm = new FMClient();

Initialization (Custom Settings)

Alternatively, pass explicit configuration options:

import { FMClient } from "@arxyf/fm";

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

Usage Examples

Fetching User Info

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

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

console.info(res.lovedTracks);
const res = await fm.user.getNowPlaying("username");

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

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

Scrobbling

Scrobble a single track, or submit several at once with scrobbleBatch.

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}`);
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);
});