A Node.js and Express backend REST API for a music streaming application. It supports role-based authentication, music file uploads, and album management.
- Runtime: Node.js
- Framework: Express.js
- Database: MongoDB (Mongoose)
- Authentication: JWT (JSON Web Tokens) & bcryptjs
- Storage: ImageKit (via
@imagekit/nodejs) - File Uploads: Multer
- Role-Based Access Control: Distinct roles for
userandartist. - Authentication: JWT-based secure login utilizing HTTP-only cookies.
- Music Uploads: Cloud storage integration with ImageKit for music file streaming.
- Album Management: Artists can group uploaded tracks into albums.
Create a .env file in the root/backend directory and configure the following variables:
PORT=3000
MONGO_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret_key
IMAGEKIT_PRIVATE_KEY=your_imagekit_private_key- Clone the repository:
git clone https://github.com/utkarrshgit/barely-spotify.git cd barely-spotify/backend - Install dependencies:
npm install
- Start the server:
The server will start on
npm run dev
http://localhost:3000.
| Method | Endpoint | Description | Access |
|---|---|---|---|
| POST | /register |
Register a new account (username, email, password, role) |
Public |
| POST | /login |
Authenticate user and set JWT cookie | Public |
| POST | /logout |
Clear JWT cookie | Public |
| Method | Endpoint | Description | Access |
|---|---|---|---|
| POST | /upload |
Upload a music file (multipart/form-data, key: music) |
Artist |
| POST | /album |
Create a new album (title, musicIds array) |
Artist |
| GET | / |
Fetch a list of music tracks | Authenticated User |
| GET | /albums |
Fetch all albums | Authenticated User |
| GET | /albums/:albumId |
Fetch specific album details and associated tracks | Authenticated User |
barely-spotify/
├── backend/
│ ├── src/
│ │ ├── controllers/
│ │ │ ├── auth.controller.js
│ │ │ └── music.controller.js
│ │ ├── db/
│ │ │ └── db.js
│ │ ├── middlewares/
│ │ │ └── auth.middleware.js
│ │ ├── models/
│ │ │ ├── album.model.js
│ │ │ ├── music.model.js
│ │ │ └── user.model.js
│ │ ├── routes/
│ │ │ ├── auth.routes.js
│ │ │ └── music.routes.js
│ │ ├── services/
│ │ │ └── storage.service.js
│ │ └── app.js
│ ├── package.json
│ ├── package-lock.json
│ └── server.js
├── .gitignore
└── README.md