Here’s a simplified and improved version of your README.md file for the Amazon Clone Backend:
This project is the backend service for an Amazon clone application. It handles user authentication, song management (CRUD operations), and other essential features using Node.js, SQL, and Prisma.
- User Authentication: Signup and Signin with JWT-based authentication.
- CRUD for Songs: Create, read, update, and delete song entries.
- Password Security: Secure password hashing using
bcrypt
. - Prisma ORM: Simplifies database operations with SQL databases.
- JWT Tokens: Used for user authentication and authorization.
- Node.js: Backend runtime environment.
- Express: Web framework for Node.js.
- Prisma: ORM for interacting with SQL databases.
- SQL Database: MySQL or SQLite (or any SQL-compatible DB).
- JWT: For managing authentication tokens.
- Bcrypt: For password encryption.
- Node.js installed.
- A SQL Database (e.g., MySQL, SQLite, etc.).
- Prisma installed and configured.
- npm or yarn for package management.
-
Clone the repository:
git clone https://github.com/your-username/amazon-clone-backend.git cd amazon-clone-backend
-
Install dependencies:
npm install
-
Set up environment variables: Create a
.env
file:touch .env
Add the following variables to the
.env
file:DATABASE_URL="mysql://user:password@localhost:3306/your-database" JWT_SECRET="your-secret-key"
-
Set up Prisma and the database: Initialize Prisma and apply migrations:
npx prisma init npx prisma migrate dev --name init
-
Start the server:
npm start
The server will run on
http://localhost:3000
.
- POST
/auth/signup
: Register a new user. - POST
/auth/signin
: Log in and receive a JWT token.
- POST
/songs
: Create a new song (requires authentication). - GET
/songs
: Get all songs. - GET
/songs/:id
: Get a specific song by ID. - PUT
/songs/:id
: Update a song by ID (requires authentication). - DELETE
/songs/:id
: Delete a song by ID (requires authentication).
- Request:
{ "email": "user@example.com", "password": "Password123" }
- Response:
{ "message": "User registered successfully", "user": { "id": 1, "email": "user@example.com" } }
- Request:
{ "email": "user@example.com", "password": "Password123" }
- Response:
{ "message": "Login successful", "token": "jwt-token-here" }
- Request:
{ "title": "Shape of You", "artist": "Ed Sheeran", "duration": 233 }
- Response:
{ "message": "Song created successfully", "song": { "id": 1, "title": "Shape of You", "artist": "Ed Sheeran", "duration": 233 } }
Ensure Prisma is properly configured in prisma/schema.prisma
:
datasource db {
provider = "mysql" // or sqlite, etc.
url = env("DATABASE_URL")
}
model User {
id Int @id @default(autoincrement())
email String @unique
password String
songs Song[]
}
model Song {
id Int @id @default(autoincrement())
title String
artist String
duration Int
userId Int
user User @relation(fields: [userId], references: [id])
}