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.
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).
index.js: Define routes and generic handlers. Start server.helpers.js: Define helper functions.db/index.js: Define database connection. Loadpg-promisewith 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.
-
Clone the repo and change into the new directory.
git clone https://github.com/falling-fruit/falling-fruit-api cd falling-fruit-api -
Install the
nodeversion specified in the.nvmrcfile. This is easiest usingnvm.nvm install nvm use
-
yarnis already provided (see.yarn/releases). Use it to install dependencies.yarn
-
Copy
.env.exampleto.envand update the values as needed.
cp .env.example .envyarn startVisit http://localhost:3300.
Validate and build the OpenAPI documentation:
yarn validate && yarn build