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

use-earworm

v1.0.0

Published

A minimal Spotify now-playing widget for React

Readme

use-earworm

A minimal Spotify now-playing widget for React. Shows what you're currently listening to or your last played track.

Install

npm i use-earworm

Quick Start

1. Set up your Spotify app

  1. Go to Spotify Developer Dashboard and create an app
  2. Set the redirect URI to http://localhost:3000/callback
  3. Note your Client ID and Client Secret
  4. Get a refresh token by following Spotify's authorization guide

2. Add environment variables

SPOTIFY_CLIENT_ID=your_client_id
SPOTIFY_CLIENT_SECRET=your_client_secret
SPOTIFY_REFRESH_TOKEN=your_refresh_token

3. Create an API route

The widget fetches data from an API route you create. use-earworm exports a getNowPlaying helper to make this easy.

Next.js (App Router)

// app/api/spotify/now-playing/route.ts
import { getNowPlaying } from "use-earworm/api";

export async function GET() {
  try {
    const track = await getNowPlaying({
      clientId: process.env.SPOTIFY_CLIENT_ID!,
      clientSecret: process.env.SPOTIFY_CLIENT_SECRET!,
      refreshToken: process.env.SPOTIFY_REFRESH_TOKEN!,
    });

    return Response.json(track ?? { isPlaying: false }, {
      headers: { "Cache-Control": "public, s-maxage=30, stale-while-revalidate=15" },
    });
  } catch {
    return Response.json({ isPlaying: false });
  }
}

Astro

// src/pages/api/spotify/now-playing.ts
import type { APIRoute } from "astro";
import { getNowPlaying } from "use-earworm/api";

export const prerender = false;

export const GET: APIRoute = async () => {
  try {
    const track = await getNowPlaying({
      clientId: import.meta.env.SPOTIFY_CLIENT_ID,
      clientSecret: import.meta.env.SPOTIFY_CLIENT_SECRET,
      refreshToken: import.meta.env.SPOTIFY_REFRESH_TOKEN,
    });

    return new Response(JSON.stringify(track ?? { isPlaying: false }), {
      headers: {
        "Content-Type": "application/json",
        "Cache-Control": "public, s-maxage=30, stale-while-revalidate=15",
      },
    });
  } catch {
    return new Response(JSON.stringify({ isPlaying: false }), {
      headers: { "Content-Type": "application/json" },
    });
  }
};

4. Add the component

import { Earworm } from "use-earworm";

export default function Page() {
  return <Earworm />;
}

Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | endpoint | string | "/api/spotify/now-playing" | API endpoint URL | | pollInterval | number | 10000 | Polling interval in ms | | activeColor | string | "#75FF4F" | Color for "LISTENING NOW" | | inactiveColor | string | "#E2E2E2" | Color for "LAST LISTEN" | | fontFamily | string | "inherit" | Font family |

How it works

  • Polls your API route every 10 seconds (configurable)
  • Shows "LISTENING NOW" with a glow effect when actively playing
  • Falls back to "LAST LISTEN" with your most recent track
  • Links to the track on Spotify
  • Shows album art, track name, and artist
  • Zero styling dependencies (no Tailwind required)
  • Renders nothing if Spotify is unreachable

License

MIT