@cored3v/web-core
v1.0.4
Published
Reusable licensed Express core for web applications
Readme
@cored3v/web-core
A generic, production-ready application core for Node.js, designed to provide reusable bootstrapping, configuration, authentication, and license-based execution enforcement across multiple frameworks.
It supports Express.js, Next.js, Nuxt (H3), and generic Node.js environments.
Features
- License Enforcement: Protect your source code by enforcing valid license keys.
- JWT Authentication: Optional, built-in JWT verification helper and middleware.
- Database Management: Optional, automatic Postgres connection pooling and lifecycle management.
- Security Defaults: Pre-configured Helmet and CORS for Express.
- Multi-Framework: First-class adapters for Express, Next.js, and H3.
Note: Only License Enforcement and Routes are mandatory. Auth and Database modules are opt-in and handled via configuration.
Installation
npm install @cored3v/web-core
# or
yarn add @cored3v/web-coreUsage
Next.js (App Router & Middleware)
Use createNextApp to integrate core services.
src/lib/core.ts
import { createNextApp } from "@cored3v/web-core";
// Initialize once (singleton pattern recommended)
export const core = await createNextApp({
appId: "my-next-app"
});src/app/api/hello/route.ts
import { core } from "@/lib/core";
import { NextResponse } from "next/server";
export async function GET(request: Request) {
// Verify Session
const user = await core.verifySession(request);
if (!user) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
return NextResponse.json({ message: "Hello World", user });
}Express.js
Use createApp to bootstrap a full Express server.
import { createApp } from "@cored3v/web-core";
await createApp({
appId: "my-express-app",
http: { port: 3000 },
routes: ({ app, router, auth, db }) => {
// Protected Route
router.get("/secure", auth.middleware(), (req, res) => {
res.json({ message: "Secure Data", user: req.user });
});
}
}).then(({ start }) => start());Nuxt / H3 / Nitro
Use createH3App for H3-based servers.
import { createH3App } from "@cored3v/web-core";
const core = await createH3App({ appId: "my-nuxt-app" });
export default eventHandler(async (event) => {
const user = await core.verifySession(event);
if (!user) {
throw createError({ statusCode: 401, statusMessage: "Unauthorized" });
}
return { message: "Success", user };
});Configuration
The library uses dotenv to load configuration. Ensure you have a .env file or environment variables set.
| Variable | Description | Required | Default |
|----------|-------------|----------|---------|
| LICENSE_PATH | Path to the license.json file | No | ./license.json |
| JWT_SECRET | Secret key for JWT verification | Yes (if auth used) | - |
| DATABASE_URL | Postgres Connection String | No | - |
| PORT | Http Port (Express only) | No | 3000 |
Note:
license.json is mandatory for the app to work. However, if the file exists in root directory, then LICENSE_PATH env variable is not required.
License
Private / Proprietary.
