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
| Module | Description |
|---|---|
| Config | Environment and file-based configuration management |
| Logger | Structured logging with multiple transports |
| Validation | Schema-based request and data validation |
| Crypto | Hashing, encryption, and token generation |
| Database | MongoDB connection management and helpers |
| HTTP | Express-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
| Variable | Default | Description |
|---|---|---|
MONGODB_URI | -- | MongoDB connection string (required) |
LOG_LEVEL | info | Logging level |
PORT | 3000 | HTTP server port |
CORS_ORIGIN | * | Allowed CORS origins (comma-separated) |
RATE_LIMIT_MAX | 100 | Max requests per window |
RATE_LIMIT_WINDOW | 60000 | Rate limit window in ms |