Skip to content

7amok4a/Jobs-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Jobs API

A RESTful API for managing job applications built with Node.js, Express, and MongoDB. This API allows users to track their job applications with features like authentication, CRUD operations, and security measures.

πŸš€ Features

  • User Authentication: Secure registration and login with JWT
  • Job Management: Create, read, update, and delete job applications
  • Security: Rate limiting, CORS, Helmet protection
  • User-specific Data: Each user can only access their own jobs
  • Input Validation: Mongoose schema validation
  • Error Handling: Comprehensive error handling middleware

πŸ“‹ Prerequisites

  • Node.js (v14 or higher)
  • MongoDB database
  • npm or yarn package manager

πŸ› οΈ Installation

  1. Clone the repository:
git clone https://github.com/yourusername/jobs-api.git
cd jobs-api
  1. Install dependencies:
npm install
  1. Create a .env file in the root directory:
PORT=3000
DB_URL=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret_key
EXPIREIN=30d
  1. Start the server:
npm start

πŸ“š API Endpoints

Authentication

Register a New User

POST /api/v1/auth/register
Content-Type: application/json

{
  "name": "John Doe",
  "email": "john@example.com",
  "password": "password123"
}

Login

POST /api/v1/auth/login
Content-Type: application/json

{
  "email": "john@example.com",
  "password": "password123"
}

Jobs (All routes require authentication)

Create a Job

POST /api/v1/jobs
Authorization: Bearer <your_token>
Content-Type: application/json

{
  "company": "Tech Company",
  "position": "Software Engineer",
  "status": "pending"
}

Get All Jobs

GET /api/v1/jobs
Authorization: Bearer <your_token>

Get Single Job

GET /api/v1/jobs/:id
Authorization: Bearer <your_token>

Update Job

PATCH /api/v1/jobs/:id
Authorization: Bearer <your_token>
Content-Type: application/json

{
  "company": "Updated Company",
  "position": "Senior Developer",
  "status": "interview"
}

Delete Job

DELETE /api/v1/jobs/:id
Authorization: Bearer <your_token>

πŸ“Š Data Models

User Model

{
  name: String (required, 3-50 chars),
  email: String (required, unique, valid email),
  password: String (required, min 6 chars, hashed)
}

Job Model

{
  company: String (required, max 50 chars),
  position: String (required, max 100 chars),
  status: String (enum: ['pending', 'interview', 'declined'], default: 'pending'),
  createdBy: ObjectId (reference to User),
  timestamps: true
}

πŸ”’ Security Features

  • Helmet: Sets various HTTP headers for security
  • CORS: Enables Cross-Origin Resource Sharing
  • Rate Limiting: Limits requests to 100 per 15 minutes
  • JWT Authentication: Secure token-based authentication
  • Password Hashing: Uses bcrypt for password encryption

πŸ—‚οΈ Project Structure

β”œβ”€β”€ controllers/
β”‚   β”œβ”€β”€ auth.controller.js
β”‚   └── jobs.controller.js
β”œβ”€β”€ database/
β”‚   └── connect.js
β”œβ”€β”€ errors/
β”‚   β”œβ”€β”€ bad-request.js
β”‚   β”œβ”€β”€ custom-error.js
β”‚   β”œβ”€β”€ notFoundError.js
β”‚   β”œβ”€β”€ unAuthError.js
β”‚   └── index.js
β”œβ”€β”€ middleware/
β”‚   β”œβ”€β”€ asyncWrapper.js
β”‚   β”œβ”€β”€ authentication.js
β”‚   β”œβ”€β”€ errorHandler.js
β”‚   └── notFoundHandler.js
β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ jobs.module.js
β”‚   └── user.module.js
β”œβ”€β”€ routers/
β”‚   β”œβ”€β”€ auth.router.js
β”‚   └── jobs.router.js
β”œβ”€β”€ .env
β”œβ”€β”€ server.js
└── package.json

🚦 Status Codes

  • 200 - OK
  • 201 - Created
  • 400 - Bad Request
  • 401 - Unauthorized
  • 404 - Not Found
  • 500 - Internal Server Error

⚠️ Error Responses

All errors follow this format:

{
  "msg": "Error message description"
}

πŸ”§ Dependencies

  • express
  • mongoose
  • bcrypt
  • jsonwebtoken
  • dotenv
  • helmet
  • cors
  • express-rate-limit
  • http-status-codes

πŸ‘€ Author

7amok4a

🀝 Contributing

Contributions, issues, and feature requests are welcome!

⭐ Show your support

Give a ⭐️ if this project helped you!

About

A secure RESTful API for tracking job applications with user authentication, built using Node.js, Express, MongoDB, and JWT. Features include CRUD operations, rate limiting, and comprehensive error handling.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors