- View Live Demo - Deployed on Vercel
Displays your Spotify currently playing track in real-time with a dynamic blurred album art background, progress bar, and clickable track link.
- 🎵 Real-time currently playing track display (polls every 3 seconds)
- 🖼️ Dynamic background based on album art
- ⏳ Smooth progress bar showing song position
- 🔒 Secure token handling via serverless function
- 🌐 Public
/api/statusendpoint for embedding in portfolio sites - 📱 Responsive design
├── api
│ ├── status.js # Public read-only endpoint — returns current track as JSON (for portfolio embeds)
│ └── token.js # Serverless function for secure Spotify token refresh
├── src
│ ├── app
│ │ └── index.js # Frontend JavaScript
│ ├── css
│ │ └── style.css # Styles
│ └── img
│ └── ico.png # Favicon
└── index.html # Main HTML file
This endpoint lets you embed a "now playing" badge on an external site (e.g. your portfolio) without exposing credentials. It returns a simple JSON object:
{
"playing": true,
"text": "Song Name – Artist",
"imageUrl": "https://...",
"spotifyUrl": "https://open.spotify.com/track/..."
}It uses BASE_URL internally to call your own /api/token endpoint, so make sure that env var is set (see Setup below).
- Create a Spotify Application through the Spotify Developer Dashboard
- Click Edit Settings
- Note down your:
Client IDClient Secret
- Under Redirect URIs, add:
http://localhost/callback/
Navigate to the following URL (replace {SPOTIFY_CLIENT_ID} with yours):
https://accounts.spotify.com/authorize?client_id={SPOTIFY_CLIENT_ID}&response_type=code&scope=user-read-currently-playing&redirect_uri=http://localhost/callback/
- After logging in, copy the
{CODE}from the redirect URL:http://localhost/callback/?code={CODE} - Create a Base64 string from
{SPOTIFY_CLIENT_ID}:{SPOTIFY_CLIENT_SECRET} - Exchange the code for a refresh token:
curl -X POST \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Authorization: Basic {BASE64}" \
-d "grant_type=authorization_code&redirect_uri=http://localhost/callback/&code={CODE}" \
https://accounts.spotify.com/api/tokenSave the refresh_token value from the response.
Need help? Watch this video tutorial by API-University.
- Clone and install:
git clone https://github.com/ArmanSingh24/my-spotify-activity.git
cd my-spotify-activity
npm install- Create a
.envfile in the project root:
CLIENT_ID=your_spotify_client_id
CLIENT_SECRET=your_spotify_client_secret
REFRESH_TOKEN=your_refresh_token
BASE_URL=http://localhost:3000
BASE_URLis required byapi/status.jsto call your local token endpoint. Set it to whatever portvercel devruns on (default is3000).
- Run locally:
vercel dev- Install Vercel CLI:
npm i -g vercel- Deploy:
vercel- Add the following environment variables in your Vercel project settings:
CLIENT_IDCLIENT_SECRETREFRESH_TOKENBASE_URL— set this to your deployed Vercel URL, e.g.https://my-spotify-activity.vercel.app
⚠️ Not recommended. The serverless functions (api/token.js,api/status.js) will not work on GitHub Pages since it only serves static files. Any workaround that moves token refresh to the client side would expose yourCLIENT_SECRETandREFRESH_TOKENpublicly — avoid this. Use Vercel or another serverless-capable host instead.
- Credentials are stored as environment variables and never exposed to the client
- The
/api/tokenendpoint uses short-lived access tokens (~1 hour) and caches them server-side - The
/api/statusendpoint is intentionally public (read-only, no credentials exposed) - Never commit your
.envfile — it's already in.gitignore
Feel free to open issues and pull requests!
- Built with the Spotify Web API
- Deployed on Vercel
Made with ❤️ by Arman Singh
