April 28, 2021

Build a REST API With Node.js, HarperDB and FastifyJS

Welcome to Community Posts
Click below to read the full article.
Summary of What to Expect
Table of Contents

Learn how to use Node.js, FastifyJS and HarperDB by building a course management REST API. This application will help you track the courses you are doing and the courses you plan to do.

Written Tutorial

Video Tutorial

  1. Set up the folder structure by creating a new folder called "course-management" and initializing a new Node.js project within it using the command "npm init -y."
  2. Install the required dependencies for the application using the command "npm i fastify harperive dotenv --save."
  3. Configure the Fastify server by creating an "app.js" file and adding the necessary code to set up the server, including importing Fastify, enabling the logger, and listening on a specified port defined in the ".env" file.
  4. Create a HarperDB Cloud Instance and configure it by setting up a schema and table to store course data.
  5. Set up the HarperDB client in the application by creating a "db_config.js" file in the "src/db" folder and initializing the HarperDB client with the instance details from the ".env" file.
  6. Create and configure the application endpoints by creating the necessary folders and files for routes and controllers.
  7. Build the logic for each endpoint using the HarperDB client to perform CRUD operations on the database.
  8. Test the application by starting the server using the command "node app.js" and accessing the different endpoints through HTTP requests.
  9. Optionally, clone the application from GitHub, install the dependencies using "npm install," and start the server with "node app.js" to run the application.