lastfm
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
A simple HTTP API that returns the top track for the most recent week from Last.fm.
lastfm.ts- HTTP endpoint that fetches and returns the top track from the past 7 daysmain.ts- Empty placeholder file
Returns the most played track for user "pinjasaur" from the past 7 days.
Response Format:
{ "track": { "name": "Track Name", "artist": "Artist Name", "playcount": 42, "url": "https://www.last.fm/music/Artist/_/Track", "image": "https://lastfm.freetls.fastly.net/i/u/300x300/image.png" }, "period": { "from": "2026-01-09T16:50:28.000Z", "to": "2026-01-16T16:50:28.000Z" }, "user": "pinjasaur" }
Error Responses:
500- API key not configured or Last.fm API error404- No tracks found for the past week
Requires the LAST_FM_API_KEY environment variable to be set with a valid Last.fm API key.
- Uses Last.fm's predefined "7day" period for better reliability
- Falls back to custom date range if needed
- Returns the largest available album artwork
- Includes caching headers (1 hour cache)
- Proper error handling and TypeScript types