Skip to Content
Getting startedEnv & secrets

Env & secrets

All secrets live in hono-backend/.env. The file src/config/env.ts reads them once at startup and exports one env object.

Rule: Never read process.env randomly in routes — import { env } from config/env.ts so validation stays in one place.

Required variables (server won’t start without these)

VariableWhat it means
MONGODB_URIAddress of your MongoDB database
GOOGLE_CLIENT_ID / GOOGLE_CLIENT_SECRETGoogle login for web/admin
JWT_ACCESS_SECRETPassword used to sign short access tokens
REFRESH_TOKEN_SECRETPassword used to hash refresh tokens in DB
YOUTUBE_API_KEYYouTube Data API for video metadata

Common optional / defaulted

VariableDefaultMeaning
PORT3000HTTP port
JWT_REFRESH_DAYS30How long refresh tokens last (must be 1–365)
ALLOWED_ORIGIN''Production web origin for CORS
OAUTH_REDIRECT_URIS''Comma-separated extra redirect URIs allowed by POST /auth/google/code (use for preview environments)
NOTIFICATION_DRY_RUNtrue in devSkip real FCM pushes when true
STREAK_WARNING_START_HOUR_IST20First IST hour (0–23) the worker may send streak warnings
STREAK_WARNING_END_HOUR_IST22Last IST hour (0–23) the worker may send streak warnings

Feature flags (boolean-ish)

Parsed by parseBool(...) in env.ts (accepts 1, true, yes, on):

  • NOTIFICATION_DRY_RUN — log pushes instead of sending.

Rate limiting

VariableDefaultMeaning
RATE_LIMIT_STOREmemoryCounter backend. memory is fast and single-instance; mongo shares counters across instances and survives restarts.
RATE_LIMIT_EVENT_SAMPLE_RATE0.01Fraction (0–1) of allowed requests that write a sampled event. Blocked and shadow violations are always recorded.

See API rate limiting for the policy / store / admin-UI story.

Current affairs search (optional Atlas features)

These are read directly by services/current-affairs-search/* from process.env — they are not on the env object, so they can be toggled per environment without restarting code that does not care.

VariableDefaultMeaning
MONGO_ATLAS_SEARCH_ENABLEDunset (regex)Truthy → use Atlas $search for CA text search instead of regex
CA_SEARCH_WINDOW_DAYS60Look-back window for CA text search
MONGO_ATLAS_VECTOR_SEARCH_ENABLEDunset (in-app)Truthy → use Atlas Vector Search instead of in-app similarity
EMBEDDING_MODELdefaultName of the embedding model used to index CA items
EMBEDDING_VERSION1Bump when re-indexing with a new model

Internal / worker

VariableUsed by
NOTIFICATION_WORKER_KEY/internal/notifications + internal-key.middleware.ts
FIREBASE_PROJECT_ID + FIREBASE_SERVICE_ACCOUNT_JSONFCM push sender (services/notifications/fcm-sender.service.ts)

Helpers inside env.ts

FunctionPurpose
require_(key)Must exist or crash
parsePositiveInt(key, fallback)Number > 0 or use default
parseBool(key, fallback)1/true/yes/on → true
parseRateLimitStore()'mongo' if env says so, else 'memory'
parseSampleRate(key, fallback)Clamps to [0, 1]
parseCsv(key)Trims and filters empty entries (used by OAUTH_REDIRECT_URIS)

See Config folder for file-level detail on env.ts and db.ts.

Last updated on