Skip to content

A RESTful backend API for managing users and tasks with authentication, role-based access control, and task CRUD operations. Built using Node.js, Express, Sequelize, and MySQL, featuring JWT authentication, user roles (admin, moderator, user), and task ownership validation.

Notifications You must be signed in to change notification settings

rayan495/nodejs-express-crud-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Task-Manager-API

A RESTful API for user authentication and task management built with Node.js, Express, Sequelize, and MySQL.


Features

  • User authentication with signup, signin, and signout functionality
  • Role-based access control: Admin, Moderator, and User
  • CRUD operations for tasks
  • Task filtering by status and pagination support
  • Secure password hashing using bcrypt
  • JWT-based authentication
  • Sequelize ORM for MySQL database interaction

Tech Stack

  • Backend: Node.js, Express
  • Database: MySQL
  • ORM: Sequelize
  • Authentication: JWT, bcrypt
  • Environment Configuration: dotenv

Getting Started

Prerequisites

  • Node.js (v14 or higher recommended)
  • MySQL database
  • npm or yarn

Installation

  1. Clone the repository:
git clone https://github.com/rayan495/Task-Manager-API.git
cd Task-Manager-API
  1. Install dependencies:
npm install
  1. Create a .env file in the root directory with your configuration:
PORT=3000
DB_NAME=your_database_name
DB_USER=your_database_user
DB_PASSWORD=your_database_password
DB_HOST=localhost
DB_DIALECT=mysql
JWT_SECRET=your_jwt_secret
  1. Run the server:
npm start

The server will run on http://localhost:3000


API Endpoints

  1. Authentication:
  • POST /auth/signup Register a new user
  • POST /auth/signin Login a user
  • POST /auth/signout Logout a user
  1. User:
  • GET /user/all Public content
  • GET /user/user Access for authenticated users
  • GET /user/admin Access for admins
  • GET /user/moderator Access for moderators
  1. Tasks:
  • POST /task Create a new task
  • GET /task Get all tasks of authenticated user
  • GET /task/user Get tasks by logged-in user
  • GET /task/:id Get task by ID
  • PUT /task/:id Update a task
  • DELETE /task/:id Delete a task (Admin/User only)

Usage

Usage:

  1. Sign up a user via /auth/signup.
  2. Login with /auth/signin to receive a JWT token.
  3. Include the JWT token in the Authorization header as Bearer to access protected routes.
  4. Create, read, update, or delete tasks based on user role and ownership.

Security

  • Passwords are hashed using bcrypt before saving to the database
  • JWT tokens are used for route protection and role-based access control

License

  • This project is open-source and available under the MIT License.

About

A RESTful backend API for managing users and tasks with authentication, role-based access control, and task CRUD operations. Built using Node.js, Express, Sequelize, and MySQL, featuring JWT authentication, user roles (admin, moderator, user), and task ownership validation.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published