Database + Environment
Orchestrate your secrets, configuration, and database connections securely using NioFlow's integrated environment management.
Environment Configuration
NioFlow utilizes a built-in environment loader that automatically detects and parses .env files in your project root. This prevents hardcoding secrets like Supabase keys or database passwords in your source code or command-line history.
Library Credit & Compliance
NioFlow's environment management is powered by the excellent dotenv-java library authored by io.github.cdimascio. We use the official, unmodified library as a dependency to ensure full security and performance standards.
Setting up your .env file
.env in your project root. NioFlow will automatically load these variables at startup.1# Server Configuration2PORT=80803JWT_SECRET=your_super_secret_signing_key_at_least_32_chars4NIOFLOW_CORS_ORIGIN=http://localhost:30005NIOFLOW_CHAOS_ENABLED=false6NIOFLOW_REPLAY_ENABLED=false7NIOFLOW_WATCH=false89# Postgres Configuration (Supabase)10JDBC_URL=jdbc:postgresql://your-db-host.supabase.co:5432/postgres11DB_USER=postgres12DB_PASS=your_secure_database_password1314# MongoDB Configuration (Atlas)15MONGO_URI=mongodb+srv://user:pass@cluster.mongodb.net/nioflow1617# Management and Token Lifecycle (v1.4.0)18NIOFLOW_METRICS_TOKEN=your-secure-management-token19NIOFLOW_JWT_EXPIRATION_MS=900000
Built-in Persistence
NioFlow provides first-class support for both relational and document-based storage. You can initialize these directly on your application instance.
1NioFlowApp app = new NioFlowApp();23// One-liner initialization from .env4app.initPostgres();5app.initMongo();67app.listen(8080);
1// Get a Postgres Connection (HikariCP)2try (Connection conn = Database.getPostgresConnection()) {3 // SQL Logic4}56// Get MongoDB Client7MongoClient mongo = Database.getMongoClient();8MongoDatabase db = mongo.getDatabase("production");
Privacy & Security
.env is added to your .gitignore file. NioFlow project generates this by default to prevent leaking credentials.Safe Parameter Extraction (v1.4.0)
To prevent injection vulnerabilities and ensure data integrity, always use the type-safe path parameter extraction methods.
1app.get("/api/tasks/:id", ctx -> {2 // Validates that :id is numeric; throws 400 if not.3 long taskId = ctx.pathParamAsLong("id");45 // Also available for Integer6 int categoryId = ctx.pathParamAsInt("category");7});
The Env API
The framework provides a unified io.github.jhanvi857.nioflow.Env class to access configuration values with ease.
1// Get String with fallback2String origin = Env.get("NIOFLOW_CORS_ORIGIN", "http://localhost:3000");34// Feature guards5boolean chaosEnabled = Env.getAsBoolean("NIOFLOW_CHAOS_ENABLED", false);6boolean replayEnabled = Env.getAsBoolean("NIOFLOW_REPLAY_ENABLED", false);7boolean watchEnabled = Env.getAsBoolean("NIOFLOW_WATCH", false);89// Get typed primitives10int port = Env.getAsInt("PORT", 8080);11boolean isDebug = Env.getAsBoolean("DEBUG_MODE", false);