The Spotify Web API allows developers to integrate Spotify’s powerful music data and playback capabilities into their applications. It provides access to Spotify’s catalog, user playlists, recommendations, track metadata, and player controls via RESTful endpoints.
- Retrieve Music Data – Get details about songs, albums, artists, and genres.
- User Authentication – Authenticate users via OAuth 2.0 to access personal Spotify data.
- Control Playback – Play, pause, skip, and modify playback on a user’s active device.
- Manage Playlists – Create, edit, and delete playlists programmatically.
- Track User Data – Access recently played tracks, top artists, and top tracks.
The following steps are intended for local hosting. If you plan to deploy the application on a server or cloud service, follow the Replit Setup.
Ensure you have Node.js installed.
Download or Clone the repository:
git clone https://github.com/H4CK3RG0D/spotifyWeb.git
cd spotifyWebInstalls all packages:
npm installStart the development server:
npm run start-
Go to the Spotify Developer Dashboard.
-
Log in and create a new application.
-
Make sure you check
Web APIunder APIs used -
Copy the Client ID and Client Secret from the application settings.
-
Under Redirect URIs, add the following URI:
http://localhost:8181/api/callback -
For local hosting, create a
.envfile in the root of your project and add the following:
SPOTIFY_CLIENT_ID=your-client-id
SPOTIFY_CLIENT_SECRET=your-client-secret
REDIRECT_URI=http://localhost:8181/api/callback6.5. For Glitch, click on the .env and add each as a variable
Save the file and restart your server if necessary.
This section explains how to set up using Glitch.com
- Go to Replit Login.
- Click Create App and select Import from GitHub
- Paste the repository URL
H4CK3RG0D/spotifyWeband import the project.
Once the project is imported, run to install all dependencies:
npm install- Add a
.envin your Replit project. - Add the following environment variables:
CLIENT_ID=your_spotify_client_id
CLIENT_SECRET=your_spotify_client_secret
REDIRECT_URI=https://something.replit.dev/api/callback
PROJECT_DOMAIN=your-replit-dev-urlTo get the PROJECT_DOMAIN, run the Replit once and you will see a webpage open. On the address bar you will see something like this: {...}.replit.dev. Copy the whole address including the subdomain.
⚠️ NOTE: The subdomain of your dev url may change, once that occurs you are to replace the domain in both.envand Spotify Dev Dash.
- Go to Spotify Developer Dashboard.
- Select your app.
- Find Redirect URIs and add:
https://something.replit.dev/api/callback - Save the changes.
- Run
http://localhost:8181/api/save-liked-songs(LOCAL) orhttps://your-glitch-project.glitch.me/api/save-liked-songs(GLITCH) to create theliked-songs.jsoninto the main directory.
To change the popularity range, update the filtering condition in the code snippet below. Adjust the threshold to suit your needs:
const tracksByMonth = likedSongsArray
.filter(song => song.popularity > 55) // POPULARITY SCORE OVER 55
...To change the artist list, simply add an artist's ID inside the artistIds array, which can be obtained by copying the artist's link through spotify url.
const artistIds = [
'3TVXtAsR1Inumwj472S9r4', // Drake
'699OTQXzgjhIYAHMy9RyPD', // Playboi Carti
'1Xyo4u8uXC1ZmMpatF05PJ', // The Weeknd
...
];For example: The Weeknd: https://open.spotify.com/artist/1Xyo4u8uXC1ZmMpatF05PJ
To change the Album Name and Description, modify the following:
const playlist = await spotifyApi.createPlaylist('ALBUMN NAME', {
description: "ALBUM DESCRIPTION",
public: true, // Public Settings
});You can customize the genre selection for randomly played songs by modifying the genres array. Simply update or extend the list to include your preferred genres. A full list of supported 1383 genres can be found here.
const genres = ['pop', 'rock', 'hip-hop', 'electronic', ...];/liked-songs: Display users' all liked songs in a.jsonformat/save-liked-songs: Imports users all liked songs into a.jsonfile with song properties/crp: Creates a "rap" playlist based on the artist listed/cmp: Creates a monthly playlist based popularity score of55+/play?uri={track-uri}: Plays a song based on inputted song uri/random-song: Plays a random song
- Add an algorithm to
/cmpbased on themes of a song - New endpoints:
/recommendations,/trending - Custom Spotify Home UI with Albums (Powered by Spicicy)
Made with ❤️ by Bryan