Skip to main content

Overview

CryptoPulse uses environment variables for configuration. Copy .env.example to .env in your project root and configure the variables below.
cp .env.example .env

Server Configuration

PORT
number
default:"3000"
The port on which the API server will listen.Example: 3000
LOG_LEVEL
string
default:"info"
Logging verbosity level. Controls the Winston logger output.Options: error, warn, info, debug, verboseExample: info

Authentication

ADMIN_USER
string
required
Username for JWT authentication via the /auth/login endpoint.Example: admin
ADMIN_PASS
string
required
Password for JWT authentication via the /auth/login endpoint.Example: secret
Use a strong password in production environments.
JWT_SECRET
string
required
Secret key used to sign JWT tokens. Must be kept secure and never exposed.Example: change-me
Generate a cryptographically secure random string for production use.
JWT_EXPIRES_IN
string
default:"1h"
JWT token expiration time. Accepts time strings like 1h, 30m, 7d.Example: 1h

Database

DATABASE_URL
string
required
PostgreSQL connection string. When running locally, use localhost. When running in Docker Compose, use the service name.Format: postgres://username:password@host:port/databaseExample (local): postgres://postgres:postgres@localhost:5432/crypto_pulseExample (docker): postgres://postgres:postgres@postgres:5432/crypto_pulse

Redis

REDIS_URL
string
required
Redis connection string. Used for batching coordination and distributed throttling. When running locally, use localhost. When running in Docker Compose, use the service name.Format: redis://host:portExample (local): redis://localhost:6379Example (docker): redis://redis:6379

Rate Limiting

THROTTLE_TTL_MS
number
default:"60000"
Throttle time window in milliseconds. Defines the rolling time window for rate limit counters.Example: 60000 (1 minute)
THROTTLE_GLOBAL_LIMIT
number
default:"20"
Maximum number of requests allowed per THROTTLE_TTL_MS window for all endpoints (excluding /docs and /docs-json).Example: 20
THROTTLE_LOGIN_LIMIT
number
default:"5"
Maximum number of login requests allowed per THROTTLE_TTL_MS window for the POST /auth/login endpoint.Example: 5

CoinGecko API

COINGECKO_API_KEY
string
required
Your CoinGecko API key for accessing cryptocurrency price data.Example: xyzGet your API key from CoinGecko.
COINGECKO_BASE_URL
string
default:"https://api.coingecko.com"
Base URL for the CoinGecko API. Typically only changed for testing purposes.Example: https://api.coingecko.com
COINGECKO_TIMEOUT_MS
number
default:"3000"
Timeout in milliseconds for CoinGecko API requests.Example: 3000

Request Batching

BATCH_WINDOW_MS
number
default:"5000"
Time window in milliseconds to wait for additional requests before flushing a batch. The first request for a coin starts this timer.Example: 5000 (5 seconds)
BATCH_THRESHOLD
number
default:"3"
Number of pending requests for the same coin that triggers an immediate batch flush, bypassing the BATCH_WINDOW_MS wait time.Example: 3
REQUEST_TIMEOUT_MS
number
default:"8000"
Maximum time in milliseconds that a single request will wait for a batch result before timing out.Example: 8000 (8 seconds)

Example Configuration

.env
PORT=3000

ADMIN_USER=admin
ADMIN_PASS=secret
JWT_SECRET=change-me
JWT_EXPIRES_IN=1h

# Use localhost when running app locally, or service name when running inside docker-compose
DATABASE_URL=postgres://postgres:postgres@localhost:5432/crypto_pulse
REDIS_URL=redis://localhost:6379

THROTTLE_TTL_MS=60000
THROTTLE_GLOBAL_LIMIT=20
THROTTLE_LOGIN_LIMIT=5

COINGECKO_BASE_URL=https://api.coingecko.com
COINGECKO_API_KEY=xyz
COINGECKO_TIMEOUT_MS=3000

BATCH_WINDOW_MS=5000
BATCH_THRESHOLD=3
REQUEST_TIMEOUT_MS=8000

LOG_LEVEL=info

Validation

All environment variables are validated on application startup using a custom validation function. Missing required variables will prevent the application from starting with a clear error message.

Build docs developers (and LLMs) love