The Jobs Manager API is a Node.js and Express-based application that provides user registration and login functionalities while allowing users to create, update, and delete job listings. It incorporates robust security measures, including Mongoose schema validation, JSON Web Tokens (JWT) for authentication, password hashing and salting, XSS protection, Helmet middleware for HTTP headers, rate limiting, input validation, CORS, and SSL/TLS encryption for data transmission security and handling of duplicate emails. The documentation is supported by Swagger UI.
- Features
- Getting Started
- Prerequisites
- Installation
- Usage
- Folder Structure
- API Endpoints
- Deployment
- Technologies Used
- Contributing
- License
- Documentation
- Import connect.js
- Invoke in start()
- Setup .env in the root
- Add MONGODB_URI with the connection string
- auth.js
- jobs.js
Email Validation Regex
const emailRegex = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
- Validate - name, password with mongoose validation
- Hash password with bcrypt
- Save user in database
- Genereate token
- Send token in response
- Validate - email, passwordin controllers
- If email or password is missing, throw BadRequestError
- Find user in database
- Compare password
- If no user or password does not match, throw UnauthenticatedErro
- If correct, generate Token
- Send token in response
- ValidationError
- Duplicate email
- CastError
- X-XSS-Protection: 1; mode=block
- Helmet: This package is used to secure your Express apps by setting various HTTP headers
- Rate Limiter: This express rate limiter is used to limit the number of requests to a certain endpoint.
- cors: Cors is used to enable cross-origin resource sharing, which allows the server to make requests from one origin to another.
/jobs/{id}:
parameters:
- in: path
name: id
schema:
type: string
required: true
description: the job id
To get started with the Jobs Manager API, follow the instructions in the sections below.
Make sure you have the following prerequisites installed:
- Node.js
- MongoDB
- npm (Node Package Manager)
- Clone this repository:
git clone https://github.com/alyconr/NodeJs-Jobs-Api.git
- Change to the directory:
cd NodeJs-Jobs-Api
- Install dependencies:
npm install
- Start the server:
npm start
-
Create a
.env
file in the project root directory and set the following environment variables:- MONGODB_URI: Your MongoDB connection URI.
- JWT_SECRET: A secret key for JWT token generation.
- JWT_LIFETIME: The lifetime of the JWT token in seconds.
- PORT: The port to run the server on.
-
Start the server:
npm start
The API should be accessible at http://localhost:8000 by default.
The project has the following folder structure:
- config/: Configuration files.
- controllers/: Request handling controllers.
- middleware/: Custom middleware functions.
- models/: Mongoose schema models.
- routes/: API routes.
- app.js: Express application setup.
- .env: Environment variables.
- .gitignore: Git ignore file.
- README.md: Documentation.
Detailed API documentation can be found in the Swagger documentation included with the project.
Please wait while server spins up... It may take one minute because the Api is deployed on a free tier of Render.com
To access the Swagger documentation locately, run the application and visit http://localhost:8000/api-docs
in your browser
The API is deployed using Render.com and hosted on Render.com as a web service.
- Node.js
- Express
- Mongoose
- Bcrypt
- JWT
- Swagger UI
- Rate Limiter
- CORS
- SSL/TLS Encryption
- Helmet
- X-XSS-Protection
- Swagger UI
The code for this project is available on GitHub: https://github.com/alyconr/NodeJs-Jobs-Api
If you would like to contribute to the project, please read the Contributing Guide.
This project is licensed under the MIT License.
You can find the documentation for this project on GitHub: https://github.com/alyconr/NodeJs-Jobs-Api/blob/main/README.md