A Node.js backend API built with Express and MySQL, featuring user authentication and management.
- User authentication (register/login)
- JWT-based authorization
- Role-based access control
- User CRUD operations
- Error handling
- MySQL databadse with Sequelize ORM
- Node.js (v14 or higher)
- MySQL server
- npm or yarn
- Clone the repository
- Install dependencies:
npm install
- Create a MySQL database named
raya_db
- Copy
.env.example
to.env
and update the values:cp .env.example .env
- Start the server:
npm run dev
- POST
/api/auth/register
- Register a new user - POST
/api/auth/login
- Login user
- GET
/api/users
- Get all users (Admin only) - GET
/api/users/:id
- Get user by ID - PUT
/api/users/:id
- Update user - DELETE
/api/users/:id
- Delete user (Admin only)
All protected routes require a Bearer token in the Authorization header:
Authorization: Bearer <token>
The API returns appropriate HTTP status codes and error messages in JSON format:
{
"message": "Error message",
"errors": [{ "field": "fieldName", "message": "validation message" }]
}