Skip to content

adamdienes/grocery_app_server

Repository files navigation

Grocery Scan App Node.js Server

This is a Node.js server for the Grocery Scan App. It provides APIs for managing grocery products using SQLite as the database.

JavaScript NodeJS Express.js SQLite DigitalOcean

Prerequisites

  • Node.js installed on your system.
  • npm (Node Package Manager) installed on your system.

Node.js CI

Installation

  1. Clone the repository:

    git clone <repository-url>
  2. Navigate to the project directory:

    cd grocery-scan-app-server
  3. Install dependencies:

    npm install
  4. Make a copy of a .env.example file in the root directory and add your environment variables:

    copy .\.env.example .env

Running the Server

To start the Node.js server, run the following command:

node server.js

API Base URL

The base URL for all API requests is localhost:PORT or https://<PROJECT_ID>.ondigitalocean.app

Authentication

API requests must include a predefined Authorization header with a valid token.

  • Key: Authorization
  • Value: Bearer <API_TOKEN>

API Routes

Get all products

  • Route: /products
  • Method: GET
  • Description: Retrieves all products from the database.

Get product by barcode

  • Route: /product/:barcode
  • Method: GET
  • Description: Retrieves a product from the database based on its barcode with ingredients list.
  • Parameters:
    • barcode: The unique identifier of the product.

Error Messages

  • 401 Unauthorized: Missing Authorization header Returned when the request does not include an Authorization header.

  • 401 Unauthorized: Invalid token Returned when the provided token in the Authorization header is invalid.

  • 404 Product not found for barcode: [barcode] Returned when no product is found in the database for the specified barcode.

DigitalOcean Droplet connection

Continuous deployment is live to a DigitalOcean Droplet, and the app is auto-updating relative to changes to the main branch.

DigitalOcean Badge

Made with ❤️ and JavaScript.