Skip to content

YounessBrunno/vanilla-node.js-task-manager-rest-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vanilla Node.js Task Manager REST API

A Task Manager REST API with Authentication, Role-Based Access, Analytics, Logging, and File-Based JSON Storage — built entirely with Node.js core modules (http, fs, crypto, events, url, path) and no external frameworks.

Features

✅ Authentication – Register, login, hashed passwords, token-based auth.
✅ Role-Based Access – User and Admin roles with different permissions.
✅ Task Management – Create, update, delete, and view tasks.
✅ Analytics – Track requests, errors, and response times in analytics.json.
✅ Logging – Store request and error logs in /logs.
✅ File-Based JSON Storage – All data (users, tasks, analytics) stored in JSON files.
✅ Error Handling – Global error handler and middleware-based validation.
✅ Pure Node.js – Built with only core modules, no frameworks.

📂 Project Structure

  • controllers/ – Request handlers for users, tasks, analytics, and health.
  • data/ – JSON file storage (users.json, tasks.json, analytics.json).
  • middleware/ – Auth, role checks, logging, error handling.
  • routes/ – API route definitions.
  • types/ – TypeScript type definitions.
  • utils/ – Helper utilities for tokens, password hashing, JSON parsing, validation.
  • server.ts – Entry point.
  • config.json – Configurable server settings.

🔑 Auth Flow

  1. Register – Create account → password hashed → saved to users.json.
  2. Login – Verify credentials → return token.
  3. Token Validation – Protect routes with Authorization: Bearer <token>.
  4. Role-Based Access – Admins can manage all; Users can only manage their own tasks.

👥 Role Differences

  • Admin
    • Manage all users and tasks.
    • Access analytics and system endpoints.
  • User
    • Manage only their own tasks.
    • No access to global analytics or system logs.

📊 System & Analytics Endpoints

  • GET /analytics → Returns request counts, errors, response times.
    Analytics Request

Analytics are stored in analytics.json.

  • GET /health → Reports uptime and status. Check Health Request

📌 Example API Requests

Register

POST /register
Content-Type: application/json
{
  "username": "john",
  "password": "Secure@123",
  "role": "user"
}

Register Request

login

POST /login
Content-Type: application/json

{
  "username": "john",
  "password": "Secure@123"
}

Login Request

getCurrentUser

GET /me
Authorization: Bearer <token>
Content-Type: application/json

Get Current User Request

createTask

POST /tasks
Authorization: Bearer <token>
Content-Type: application/json

{
  "title": "Finish API",
  "description": "Write controllers and test with Postman",
}

Create Task Request

getAllTasks

GET /tasks
Authorization: Bearer <token>
Content-Type: application/json

Get All Tasks Request

getTaskById

GET /tasks/:id
Authorization: Bearer <token>
Content-Type: application/json

Get Task By Id Request

updateTask

PUT /tasks/:id

Authorization: Bearer <token>
Content-Type: application/json

{
    "title": "Finish API",
    "description": "Write controllers and test with Postman",
    "status": "done",
    "priority": "high"
  
}

Update Task Request

deleteTask

DELETE /tasks/:id

Authorization: Bearer <token>
Content-Type: application/json

Delete Task Request

🛠️ Tech Stack

⚡ Backend Core

  • Node.js (Core Modules Only) – Built entirely without frameworks like Express.

📝 Type Safety

  • TypeScript – Strong typing, cleaner code, and better scalability.

💾 Data Layer

  • JSON File Storage – Lightweight, file-based storage instead of a database.

About

Vanilla Node.js Task Manager REST API with Authentication, Role-Based Access, Analytics, Logging, and File-Based JSON Storage, built entirely with Node core modules (http, fs, crypto, events, url, path).

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors