Skip to main content

Core Wire

The Core wire (@fluxkitdev/core) is the foundation of every FluxKit application. It provides essential infrastructure services that all other wires depend on.

Installation

npm install @fluxkitdev/core

What's Included

ModuleDescription
ConfigEnvironment and file-based configuration management
LoggerStructured logging with multiple transports
ValidationSchema-based request and data validation
CryptoHashing, encryption, and token generation
DatabaseMongoDB connection management and helpers
HTTPExpress-based HTTP server with middleware

Quick Example

import { FluxKit } from "@fluxkitdev/core";

const app = new FluxKit({
database: {
uri: "mongodb://localhost:27017/myapp",
},
logger: {
level: "debug",
},
});

// Access core utilities directly
app.logger.info("Application starting");
app.config.get("MY_VAR");

await app.start({ port: 3000 });

Configuration

The core wire is configured through the FluxKit constructor or environment variables:

const app = new FluxKit({
database: {
uri: process.env.MONGODB_URI,
dbName: "myapp",
},
logger: {
level: "info", // "debug" | "info" | "warn" | "error"
format: "json", // "json" | "pretty"
},
server: {
cors: {
origin: ["http://localhost:5173"],
credentials: true,
},
rateLimit: {
windowMs: 60_000,
max: 100,
},
},
});

Environment Variables

VariableDefaultDescription
MONGODB_URI--MongoDB connection string (required)
LOG_LEVELinfoLogging level
PORT3000HTTP server port
CORS_ORIGIN*Allowed CORS origins (comma-separated)
RATE_LIMIT_MAX100Max requests per window
RATE_LIMIT_WINDOW60000Rate limit window in ms