Backend API for Biendata, serving species, ranges, observations, occurrences, and trait data with download support. Built with Node.js and Express, backed by PostgreSQL.
- Species & range data — Lookup and query species, ranges, and species-range associations
- Observations & occurrences — Single and bulk (multi-species) observation/occurrence queries
- Trait data — Trait lookups and downloads
- Download endpoints — CSV/ZIP exports for observations, ranges, and traits (single and bulk)
- Rate limiting — 100 requests per 15 minutes per IP on
/apiroutes - CORS — Allowed origins:
biendata.org,www.biendata.org, andmint-pheasant.nceas.ucsb.edu:3004
- Node.js (v14 or later)
- PostgreSQL — Two databases are used: one for main app data (
PGDATABASE), one for traits/occurrences/species-ranges (PGDATABASE2)
-
Clone and install
npm install
-
Environment variables
Create a
.envfile in the project root with:PORT=3005 PGHOST=localhost PGUSER=your_user PGPASSWORD=your_password PGDATABASE=your_main_database PGDATABASE2=your_secondary_database PGPORT=5432
PGDATABASE— Used byconfig/db.jsand most range/observation logicPGDATABASE2— Used by trait, occurrence, and species-range controllers
-
Run the server
npm start
Server listens on
PORT(default3005).
| Command | Description |
|---|---|
npm start |
Start server (node server.js) |
npm test |
Placeholder (no tests yet) |
All API routes are under /api. Rate limit: 100 requests per 15 minutes per IP.
| Base path | Description |
|---|---|
/api/species |
Species lookup |
/api/range |
Range data and range queries |
/api/species-ranges |
Species–range associations |
/api/observations |
Observation queries |
/api/occurrences |
Occurrence queries |
/api/multi-occurrences |
Bulk occurrence records |
/api/multiple-species |
Multi-species lookups |
/api/multiple-ranges |
Multi-species range data |
/api/multiple-observations |
Multi-species observation lookups |
/api/traits |
Trait data |
/api/download |
Observation, range, and trait downloads (single and multi) |
Download routes support CSV and ZIP. Geometry is handled with wkx where applicable.
├── config/
│ └── db.js # PostgreSQL pool (PGDATABASE)
├── controllers/ # Route handlers and DB logic
├── middleware/
│ └── errorHandler.js # Global error handler
├── routes/ # Express routers
├── server.js # App entry, CORS, rate limit, route mounting
├── package.json
└── README.md
MIT