Create a JOB listing CRUD REST-API using JavaScript , Node.JS, MongoDB

Create a JOB listing CRUD REST-API using JavaScript , Node.JS, MongoDB

Hi! Y’all hope you guys are pumped up for this short tutorial.

This was given as an backend internship assignment to me. I thought of posting a blog about it; Why not lol😂.

job-interview-meme-17

let’s have an quick high level overview of the project.

Requirements of the project:

  • User Authentication

    • Users can sign up, log in, and authenticate using JWT-based (JSON Web Token) authentication.

    • Passwords are securely stored using bcryptjs.

  • Job Management

    • Users can view available jobs and apply for them.

    • Only admin users have the permission to create new job listings.

  • Role-Based Access Control

    • Role-based system where admin users have elevated privileges to manage job posts, while normal users can only view and apply for jobs.
  • User Management

    • Admins can manage users by viewing user profiles.

    • Users can like other users, and the liked user's points increase.

High level overview of the project

We’ll be diving into making a simple CRUD application for listing newly posted jobs.

let’s list down the API endpoints(routes) for this project

  • User Routes:

    • GET /users: Retrieve a list of all users.

    • POST /users: Create a new user by providing a name, GitHub link, and password.

    • POST /users/:id/like: Like a specific user by their ID.

  • Job Routes:

    • GET /jobs: View all available jobs.

    • POST /jobs: Create a new job with a title and link (Admin-only).

    • POST /jobs/:id/apply: Apply for a specific job by ID (Requires JWT authentication).

Ok now let’s setup the project!!!

  • But before that Here is the GitHub repository link in case you miss something ,I got you Covered😎clone the remote repository and see it. If you want to make changes you’re more than welcome fork the repo and make a pull request

  •     git clone https://github.com/Sumit0071/Job_listing_CRUD.git
    
  • now make a list of folder and files like this

  • Make sure that your package.json file looks like this

  • Install all the dependencies listed in your app

npm install
  • Navigate to your app.js file and complete it

  • let’s configure the database(MongoDB) here we’re using mongoose ORM to map our mongo atlas database with the server to connect with our application

  • Now let’s make the Schema for the Jobs and Users

  • Let’s write the routes of the application navigate to routes folder and complete the files

  • userRoutes.js

  • jobRoutes.js

  • write the middleware function to authenticate before giving authorization to the routes.Navigate to middleware folder

  • now let’s come to the main part that is let’s write the business logic behind the application navigate to your controllers folder

  • usercontroller.js

  • jobcontroller.js

  • make a .env file with this format replace your specific url in the mentioned position

Now all done. Let’s test if our API is working fine or not?

Go to Postman and create a new collection JobListing to test out our Api

create a POST request with admin designation

Now copy the generated token and paste it in headers

now login as admin

Create jobs

see the jobs with the get request as well,and use other the defined routes to test out the API.

Job WELL done! - Meme - MemesHappen

If You guys have any doubts feel free to reach me out on linkedin, Instagram

LinkedIn

Instagram

Please like the post and leave a comment It means a lot!!!😍

pleaseeee up vote >.< : r/HappyUpvote