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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@meertarbani/spotify-api-js

v0.0.5

Published

Advance Spotify API Wrapper for Node.js and Browser

Downloads

4

Readme

Spotify API Wrapper for Node.js/Bun.js

This module (created using bun.js) provides a wrapper for the Spotify API, allowing developers to easily access information about a user's currently playing song and recently played tracks.

Installation

To install this package, simply use npm:

npm install @meertarbani/spotify-api-js
                or
bun add @meertarbani/spotify-api-js

Usage

Before using this module, you need to obtain the following credentials from Spotify:

  • SPOTIFY_CLIENT_ID: Your Spotify client ID
  • SPOTIFY_SECRET_ID: Your Spotify secret ID
  • SPOTIFY_REFRESH_TOKEN: Your Spotify refresh token

You can obtain these credentials by following the steps outlined in the Setting Up Spotify API Credentials guide. Once you have obtained these credentials, you can use this module as follows:

import { SpotifyClient } from "@meertarbani/spotify-api-js";

// Initialize the SpotifyClient with the required environment variables

const client = new SpotifyClient({
  SPOTIFY_CLIENT_ID: process.env.SPOTIFY_CLIENT_ID as string,
  SPOTIFY_REFRESH_TOKEN: process.env.SPOTIFY_REFRESH_TOKEN as string,
  SPOTIFY_SECRET_ID: process.env.SPOTIFY_SECRET_ID as string,
});

Once you have initialized the SpotifyClient, you can use the following methods to access information about the user, user's currently playing song, recently played tracks etc:

Get User's Profile

// Get current user's profile
const profile = await client.getUserProfile();

// Log the results
console.log(profile);

Get User's Currently Playing Track

// Get the current playing track
const nowPlaying = await client.getNowPlaying();

// Log the results
console.log(nowPlaying);

Get User's Recently Played Tracks

// Get the recently played tracks
const recentlyPlayed = await client.getRecentlyPlayed({
  // Optional parameters
  nextUrl:
    "https://api.spotify.com/v1/me/player/recently-played?before=1707503673732", // if you want to get the next set of recently played tracks!
  limit: 50, // if you want to limit the number of recently played tracks max 50!
  after: timestamp, // if you want to get the recently played tracks after: timestamp,
  before: timestamp, // if you want to get the recently played tracks before: timestamp,
});

// Log the results
console.log(recentlyPlayed);

Get Any API Endpoint

// Get any API endpoint that hasn't been implemented yet
const customAPI = await client.getCustomAPI("https://api.spotify.com/v1/me/player"); // pass the endpoint you want to get!

// Log the results
console.log(customAPI);

Contributing

Contributions are welcome! If you find any bugs or have suggestions for improvements, please open an issue or submit a pull request on GitHub.

License

This project is licensed under the MIT License - see the LICENSE file for details.