Backend service for the Music Library platform.
This service provides REST APIs for:
- Fetching live Suno play counts
- Tracking native library play counts
- Caching Suno play counts for improved performance
- Storing library play counts using SQLite
- Live Suno play count scraping
- 5-minute in-memory caching for Suno play counts
- Native library play count tracking
- SQLite database with automatic initialization
- Atomic play count updates using SQLite UPSERT
- Input validation
- Consistent JSON API responses
- Graceful server shutdown
- Node.js
- Express.js
- SQLite3
- CORS
Clone the repository:
git clone https://github.com/ranchimall/musicLibraryAI-backend.git
cd musicLibraryAI-backendInstall dependencies:
npm installStart the server:
npm startThe server will start on:
http://localhost:3000
| Variable | Default | Description |
|---|---|---|
PORT |
3000 |
Port used by the server |
Example:
PORT=5000 npm startFetches the latest play count from a Suno song.
Endpoint
GET /api/suno-plays
Query Parameters
| Parameter | Description |
|---|---|
url |
Suno song URL |
Example:
GET /api/suno-plays?url=https://suno.com/s/xxxxxxxx
Response:
{
"success": true,
"playCount": 25431,
"cached": false
}If the play count is served from cache:
{
"success": true,
"playCount": 25431,
"cached": true
}Returns the native play count stored by the library.
Endpoint
GET /api/platform-plays
Query Parameters
| Parameter | Description |
|---|---|
id |
Track ID |
Example:
GET /api/platform-plays?id=track-id
Response:
{
"success": true,
"playCount": 42
}Increments the native library play count by one.
Endpoint
POST /api/platform-plays
Query Parameters
| Parameter | Description |
|---|---|
id |
Track ID |
Example:
POST /api/platform-plays?id=track-id
Response:
{
"success": true,
"playCount": 43
}musicLibraryAI-backend/
│
├── data/
│ └── plays.db
├── server.js
├── package.json
├── package-lock.json
├── README.md
└── .gitignore
The backend automatically creates a SQLite database on startup.
Table:
plays
-----------------------------
track_id TEXT PRIMARY KEY
play_count INTEGER DEFAULT 0
Library play counts are updated using SQLite's UPSERT feature, ensuring atomic updates.
To reduce requests to Suno, play counts are cached in memory.
- Cache duration: 5 minutes
- Expired cache entries are cleaned automatically every minute.
This backend can be deployed to any Node.js hosting provider.
Supported platforms include:
- Render
- Railway
- Fly.io
- VPS
- Docker
Runtime
Node
Build Command
npm installStart Command
npm starthttp://localhost:3000
Replace with your deployed backend URL:
https://your-render-app.onrender.com
- Library play counts are stored in SQLite.
- Suno play counts are fetched live and cached temporarily.
- Cached Suno play counts expire automatically after five minutes.
- On platforms with ephemeral storage (such as Render's free tier), the SQLite database may be reset after a service restart. For production deployments, use a persistent database such as PostgreSQL if permanent storage is required.
This project is part of the Music Library platform.