This project is a Job API built using Node.js and Express.js, providing endpoints for user registration, login, updateUser, and job management. It incorporates security measures such as helmet and xss-clean.
Follow the steps below to set up and run the project:
-
Create a
.env
file in the project root directory. -
In the
.env
file, set the required variables such asMONGO_URI
for MongoDB connection and other environment-specific variables.MONGO_URI=your_mongodb_connection_string JWT_KEY=your_jwt_secret JWT_LIFETIME=your-lifetime-jwt
-
Open your terminal and run the following commands:
npm install npm start
This will install the required dependencies and start the server.
The project is organized into the following directories:
- controllers: Contains the logic for handling HTTP requests.
- db: Manages the database connection and schema.
- errors: Handles custom error classes.
- middleware: Includes security middleware functions (helmet, cors, xss-clean), and rate limiting.
- models: Defines the data models for users and jobs.
- routes: Defines the API routes.
- helmet: Helps secure the application by setting various HTTP headers.
- xss-clean: Sanitizes user input to prevent Cross-Site Scripting (XSS) attacks.
- POST /register: Register a new user.
- POST /login: Log in as an existing user.
- PATCH /updateUser: Update user name or city... .
- GET /jobs: Get all jobs.
- GET /jobs/:id: Get a specific job by ID.
- POST /jobs: Create a new job.
- PUT /jobs/:id: Update a job by ID.
- DELETE /jobs/:id: Delete a job by ID.
- GET /jobs/stats: Get stats for jobs.
You can see this project here.
Feel free to contribute by opening issues or submitting pull requests. Make sure to follow the existing code style and conventions.
This project is from John Smilga.