An open API service indexing awesome lists of open source software.

https://github.com/fikriaf/music-api

Backend Music API with Some Parameter
https://github.com/fikriaf/music-api

api backend express music-api

Last synced: 6 months ago
JSON representation

Backend Music API with Some Parameter

Awesome Lists containing this project

README

          

# 🎧 Faftech Music API

Faftech Music API is a lightweight Node.js + Express application designed to serve and upload `.mp3` audio files, complete with metadata duration extraction. It exposes two key endpoints: one for retrieving a list of available music files, and another for uploading new files.

---

## 📦 Features

- 🚀 Fast and simple API for `.mp3` files
- 📁 Static serving of uploaded audio
- 🕒 Extracts duration from audio metadata
- 🎯 Supports cross-origin requests (CORS)
- ⬆️ Upload `.mp3` via `multipart/form-data`

---

## 🛠️ Tech Stack

- Node.js
- Express.js
- Multer (for handling file uploads)
- music-metadata (to parse audio metadata)
- TypeScript (optional)

---

## 📂 Folder Structure

```
faftech-music-api/
├── public/
│ └── audio/ # Uploaded .mp3 files are saved here
├── src/
│ └── index.ts # Main Express app
├── package.json
├── tsconfig.json # TypeScript config (if applicable)
└── README.md
```

---

## 🔧 Setup

### 1. Clone the repository

```bash
git clone https://github.com/fikriaf/Music-API.git
cd Music-API/faftech-music-api
```

### 2. Install dependencies

```bash
npm install
```

### 3. Run the server

```bash
npm start
```

Or with TypeScript (if available):

```bash
npx ts-node src/index.ts
```

---

## 📡 API Endpoints

### `GET /api/music`

Returns a list of all `.mp3` files with metadata:

**Response:**
```json
[
{
"id": 1,
"title": "Sample Track",
"file": "sample.mp3",
"url": "/audio/sample.mp3",
"duration": "2:34"
}
]
```

### `POST /api/upload`

Upload `.mp3` file using `multipart/form-data`. Field name must be `file`.

**Request:**
```http
POST /api/upload
Content-Type: multipart/form-data
```

**Form field:**
- `file`: The `.mp3` file to upload

**Response:**
```json
{ "message": "Upload berhasil", "file": "track.mp3" }
```

---

## 🌍 CORS

CORS is enabled for all origins.

---

## 📝 License

MIT