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

@hansogj/discogs-cover

v1.3.0

Published

A library and CLI to find and download album cover art from Discogs.

Downloads

18

Readme

Discogs Cover Art Finder

A simple and powerful tool to find and download the main cover art for any album from Discogs. It can be used as a command-line tool or as a library in your own Node.js projects. Now in TypeScript!

Setup

This project uses pnpm as its package manager.

  1. Install pnpm: If you don't have pnpm, you can install it globally with npm:

    npm install -g pnpm
  2. Clone the repository and install dependencies:

    pnpm install
  3. Create a .env file: Copy the .env.example to a new file named .env.

    cp .env.example .env
  4. Get a Discogs Personal Access Token:

    • Go to your Discogs Developer Settings.
    • Click "Generate new token".
    • Copy the generated token.
  5. Add your token to the .env file: Open your .env file and paste your token:

    DISCOGS_TOKEN=YourDiscogsTokenGoesHere
  6. Build the project: This project is written in TypeScript. You need to compile it to JavaScript before running.

    pnpm build

CLI Usage

After building the project (pnpm build), you can run the CLI. It will interactively prompt you if multiple matches are found.

Syntax:

node dist/src/cli.js -artist="<Artist Name>" -title="<Album Title>" [-target="</path/to/save>"]

Or using the pnpm script:

pnpm cli -- -artist="<Artist Name>" -title="<Album Title>" [-target="</path/to/save>"]

Arguments:

  • -artist: The name of the artist (required).
  • -title: The title of the album (required).
  • -target: The folder where cover.jpg will be saved. Defaults to the current directory (.).

Example:

pnpm cli -- -artist="Daft Punk" -title="Discovery" -target="./downloads"

If you install the package globally (pnpm add -g .), you can use the command directly:

discogs-cover -artist="Daft Punk" -title="Discovery"

Library Usage

You can import the core function into your own Node.js projects to programmatically fetch cover art.

Installation:

pnpm add @hansogj/discogs-cover

Using Environment Variables (.env)

The discogsMainCover function is designed to automatically use the DISCOGS_TOKEN from your environment variables. To load this token from a .env file in your own project, you'll need the dotenv package.

  1. Install dotenv:

    pnpm add dotenv
  2. Load the .env file at the very start of your script by adding import 'dotenv/config';.

This setup allows you to call discogsMainCover without manually passing the token, as it will be picked up from process.env.

Example (TypeScript):

import { discogsMainCover } from '@hansogj/discogs-cover';
import * as fs from 'node:fs';
import 'dotenv/config'; // Load environment variables from .env file

// --- Get the first result automatically (using async/await) ---
async function getFirstCover() {
  try {
    // No need to pass the token here, it's read from process.env.DISCOGS_TOKEN
    const imageBuffer: Buffer = await discogsMainCover({
      artist: 'Daft Punk',
      title: 'Discovery',
      strategy: 'first', // 'first' is the default
      // token: "MY_SECRET_TOKEN", // optional, will default to DISCOGS_TOKEN from `.env`
    });
    fs.writeFileSync('daft-punk-cover.jpg', imageBuffer);
    console.log('Cover saved!');
  } catch (error) {
    if (error instanceof Error) {
      console.error(error.message);
    } else {
      console.error('An unknown error occurred', error);
    }
  }
}

getFirstCover();

// --- Prompt the user if multiple matches exist ---
async function getCoverWithPrompt() {
  try {
    const imageBuffer: Buffer = await discogsMainCover({
      artist: 'Radiohead',
      title: 'OK Computer',
      strategy: 'prompt', // Will ask user to choose from a list
    });
    fs.writeFileSync('radiohead-cover.jpg', imageBuffer);
    console.log('Cover saved!');
  } catch (error) {
    if (error instanceof Error) {
      console.error(error.message);
    } else {
      console.error('An unknown error occurred', error);
    }
  }
}

getCoverWithPrompt();