Skip to content

falling-fruit/falling-fruit-api

Repository files navigation

Status

Falling Fruit API

NodeJS API using express, pg-promise, and bluebird. The code structure is inspired by this pg-promise demo and this more general tutorial.

You can browse the OpenAPI definition for the main branch here, and for the live API here.

Status

Live at https://fallingfruit.org/api/0.3. Used by https://fallingfruit.org (falling-fruit) and extensively by https://beta.fallingfruit.org (falling-fruit-web).

Layout

  • index.js: Define routes and generic handlers. Start server.
  • helpers.js: Define helper functions.
  • db/
    • index.js: Define database connection. Load pg-promise with repos:
    • repos/
      • index.js: Compile all classes:
      • {class}.js: Class definition with methods.
    • sql/
      • index.js: Load all SQL query files:
      • {class}/
        • *.sql: Raw SQL with variable substitutions.

Development

Installation

  1. Install Node JS
  2. Install Yarn
  3. Clone this repo, cd into the directory, and install node modules:
git clone https://github.com/falling-fruit/api.git
cd api
yarn
  1. Copy .env.example to .env and update the values as needed.
cp .env.example .env

Usage

  1. Run yarn start
  2. Visit http://localhost:3300