DEV Community

Cover image for Creating a job board with Node.js and FaunaDB - Part 1
Luis Felipe Ciochetta
Luis Felipe Ciochetta

Posted on • Updated on

Creating a job board with Node.js and FaunaDB - Part 1

In the last couple days, I've built the back-end for a to-do list with FaunaDB, and it got me really interested, so I've decided to explore more about this database and build something a little more complex.

My idea here is to build the back-end for something like Angelist, Indeed or Linkedin('s jobs board)


Notes

  • This post in particular is a translation of a post I've done some days ago, so any feedback here won't affect the next post (cause it's already written)

  • This posts will literally be a documentation of my studies, so I will probably be wrong about the way I do things a lot of times, I would really appreciate some feedback when that happens.

  • This chould change as I go, but I have no intention of create authentication for this project.


Content

Notoriously what is not in this post are the modules, this first article took me way more time than I thought it would, so I will start the modules in the future articles


About the app

Users

This app will have two users in mind

  • Companies who wanna hire people
  • Candidates who want to be hired

Functionalities

  • Registration, for each user type.
  • Job offer creation.
  • Notifying candidates when there is a new job offer that they fulfill the requisites for.
  • A match system that will share their information if both the company and the candidate see each other as a fit.
  • Search for candidates to search for job offers and companies and for companies to search for candidates.

Data modelling

First of all, I think it's important to say that I thought this would be the hardest part, for my experience with both SQL and NoSQL, it's very easy to get the data modelling wrong and create a lot of rework for yourself in the future.

However, while I was writing this post, I found another post here in Dev.to (which will be linked in the end) about data modelling in FaunaDB, and it happens that it's possible to easily restructure the data models while the database is already being used.

Alright, about the models;

So far, I've thought about four models:

  • Company
  • Candidate
  • Job post
  • Skill

Companies and candidates will be our users.

Job posts will be the posts companies will make.

Skills will be in the candidates profiles and in the job offerings and requisites.

One by one, I will talk about the fields for each model and create a pseudo code of how I think the class will look like.

Company

Companies will need a identification (name and email), they will need a description (kind of a bio), and links for their websites and social media

Company {
  name: "fake company",
  email: "fake@compa.ny",
  description: "we do not exist",
  social_media: [
    { name: "twitter", link: "https://twitter.com/fakecompany" },
   . . .  
  ]  
}
Enter fullscreen mode Exit fullscreen mode

Candidate

As the company, candidates will need identification (name and email), as well as links for their social media acounts. Besides that, candidates will need a bio and a list of skills

This list of skills will be a list of references to the skill model and a level of proficiency and that skill

Candidate {
  name: "fake candidate",
  email: "someone@gmail.com",
  bio: "was literally just created",
  social_media: [
    { name: "twitter", link: "https://twitter.com/fake_candidate" },
   . . .  
  ],
  skills: [
    { skill_ref:"12345678", experience: "advanced" },
    . . .
  ]
}
Enter fullscreen mode Exit fullscreen mode

Job posts

Job posts will have to be associated with a company, will also need a title, a description, a list of pre-requisites and a list of candidates

JobPosting {
  title: "Senior fake position",
  company_ref: "123123123",
  description: "we need a ninja fake employee",
  requisites: [
    { skill_ref: "123123", experience: "medium" },
   . . .  
  ],
  applicants: [
    { candidate_ref:"1234321" },
    . . .
  ]
}
Enter fullscreen mode Exit fullscreen mode

Skills

Skill will only need a name. Their purpose is only to be referenced by other models (candidates and job posts)

Skill{
  name: "journalism"
}
Enter fullscreen mode Exit fullscreen mode

Creating the database

I will be using the free version of Fauna for this study, you can get it in this link.
In this account, I will create a database:

Creating the database

And inside it a table for each of the models I've talked about:

Creating a table

And then insert a document in each of the tables:

Creating the document


Creating the project and installing dependencies

First thing, I will create a folder and initialize a node project inside of it:

npm init -y
Enter fullscreen mode Exit fullscreen mode

After that I will install Express, the body-parser, Fauna's driver and dotenv with the following commands:

npm install express
npm install body-parser
npm install faunadb
npm install dotenv

Enter fullscreen mode Exit fullscreen mode

A quick explanation about each of those:

  • Express: server framework, I will use it for the routes and some middleware.
  • Body-parser: A middle for express that makes it easy to get a json from the requests.
  • Faunadb: driver I will use to connect with my database.
  • dotenv: A library that gets my .env file and makes it's information acessible in the code.

Structuring the project

I will organize this project's structure by modules, being one module for each of the models I've created during the modelling. I usually use this structure because it's clean and easy to navigate.

(but if I am being honest, it's because I've read this github and got convinced to follow some of their standards)

So the project will look like this:

In the root, I will keep files that apply to every module, and then each module will have their own routes, controllers and utils files


Beginning the app

First thing, I will create a index.js and throw all the information about express a initialize the body-parser

It's considered a good practice to separate the server initialization from the index file, so I will possibly change this in the future, but for now, I will just keep it this way.

After that, I will create a file called db.js and write the Fauna initialization there:

What this code is doing, is creating a new Fauna client and exporting it and also the query from Fauna, so I can create queries in other files.

After that, I will create the file routes.js, where I will keep a reference for the other modules:

I've left a comment in there for how I imagine the reference for each module will be done.

After that, I've added the reference to the router in index:


Conclusion

Well, with that I have the structure I will need to start writing the modules.

This is the repository for the project:

https://github.com/ciochetta/faunajobboard

Link I've used to study:

Top comments (0)