A Node.js + TypeScript REST API built with Express and PostgreSQL.
- Node.js 18+
- npm or yarn or pnpm
- PostgreSQL (if using the database locally)
- Install dependencies:
npm install- Create environment file:
cp .env.example .envEdit .env with your values. Common variables:
PORT=3000
DATABASE_URL=postgres://user:password@localhost:5432/encovia
npm run dev— Start the server in watch mode with tsx.npm run build— Compile TypeScript todist/.npm start— Run the compiled server fromdist/.
- Source code lives in
src/(entry:src/index.ts). - Built files output to
dist/(entry:dist/index.js).
Run in watch mode during development:
npm run devBase URL: http://localhost:${PORT} (default 4000 if not set)
-
Health
- Method: GET
- Path:
/health - Response:
{ ok: true }
-
Create Place
- Method: POST
- Path:
/places - Request body JSON:
namestring (required)descriptionstring (optional)categorystring (required)latitudenumber (required)longitudenumber (required)addressstring (optional)additionalInfostring (optional)
- Success 201 response:
{ id: string }
- Error 400:
{ error: 'Invalid payload' }
Example:
curl -X POST http://localhost:4000/places \ -H 'Content-Type: application/json' \ -d '{ "name":"Community Garden", "description":"Shaded benches", "category":"park", "latitude":5.6037, "longitude":-0.1870, "address":"12 Palm St", "additionalInfo":"water tap nearby" }'
-
List Places
- Method: GET
- Path:
/places - Success 200 response (array of places):
idstringnamestringdescriptionstringcategorystringlocationobjectlatitudenumberlongitudenumber
addressstringadditionalInfostringisUserContributedbooleancreatedAtstring (ISO timestamp)
Example:
curl http://localhost:4000/places
-
Nearby Places
- Method: GET
- Path:
/places/nearby - Query:
latnumber (required)lonnumber (required)radius_kmnumber (optional, default10)
- Response: same shape as List Places (array filtered by Haversine distance)
Example:
curl 'http://localhost:4000/places/nearby?lat=5.6037&lon=-0.1870&radius_km=5' -
Daily Content (Fact + Action)
- Method: GET
- Path:
/daily - Query:
dayinteger 1–180 (optional). If omitted or out of range, uses today mapped into 1–180.
- Success 200 response:
dayIndexintegerfactstringactionstring
Example:
curl http://localhost:4000/daily curl 'http://localhost:4000/daily?day=42' -
Daily Fact only
- Method: GET
- Path:
/daily/fact - Query:
dayinteger 1–180 (optional) - Success 200 response:
dayIndexintegerfactstring
Example:
curl http://localhost:4000/daily/fact curl 'http://localhost:4000/daily/fact?day=42' -
Daily Action only
- Method: GET
- Path:
/daily/action - Query:
dayinteger 1–180 (optional) - Success 200 response:
dayIndexintegeractionstring
Example:
curl http://localhost:4000/daily/action curl 'http://localhost:4000/daily/action?day=42'
Tables daily_facts and daily_actions are created on startup if missing. To seed 180 rotating entries:
psql "$DATABASE_URL" -f scripts/seed_daily_content.sqlBuild and start:
npm run build
npm startThis project uses dotenv. Do not commit real secrets. Keep only example keys in .env.example.
Proprietary