June 11, 2021

JavaScript CRUD REST API using Node.js, Express, HarperDB, Docker

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

A step-by-step procedure from scratch that will guide you through the process of creating the APIS and dockerize the project

  1. Set Up Project Structure: Create a folder named "harperdb-docker" and navigate into it.
  2. Initialize Node.js Application: Use npm to initialize a Node.js application.
  3. Install Dependencies: Install necessary dependencies: express (web framework) and harperive (HarperDB connection).
  4. Create Application Structure: Organize project files by creating directories for controllers, routes, and utilities.
  5. Configure Express App: Set up an Express app in "index.js" with required middleware and route handling.
  6. HarperDB Connection: Create a connection to HarperDB in a "database.js" file inside the "util" folder.
  7. Create Test Endpoint: Design a test endpoint "/dev/version" in "dev.routes.js" to verify application functionality.
  8. Create CRUD Endpoints: Design CRUD endpoints in "users.routes.js" for creating, reading, updating, and deleting users.
  9. Implement Controllers: Create controller files for "dev" and "users" routes to handle requests and interact with HarperDB.
  10. Docker Setup: Create Docker configuration files: Dockerfile, docker-compose.yml, and .dockerignore.
  11. Configure Dockerfile: Set up Dockerfile with instructions for building the Docker image.
  12. Define docker-compose.yml: Create a docker-compose.yml file to manage the Docker service.
  13. Create .env File: Set environment variables in a ".env" file for Docker container configuration.
  14. Build Docker Image: Build the Docker image for the backend service.
  15. Run Docker Container: Start the application in a Docker container.
  16. Test Endpoints: Use Postman or HarperDB UI to test endpoints, such as "/dev/version".
  17. CRUD Operations: Test CRUD operations by sending requests to user-related endpoints.
  18. Monitor in UI: Monitor the database entries and operations using HarperDB UI.