Express Target
Compile KERN to Express.js backend APIs. Server, route, middleware, and schema nodes generate a fully structured Express application with typed handlers.
What it generates
KERN input:
server name=API port=3000
middleware name=cors
middleware name=auth
route method=get path=/api/users
schema response=User[]
handler name=listUsers
route method=post path=/api/users
schema body=CreateUser response=User
handler name=createUserCompiled output:
import express from 'express';
import cors from 'cors';
import { auth } from './middleware/auth';
import { listUsers, createUser } from './handlers';
const app = express();
app.use(express.json());
app.use(cors());
app.use(auth);
app.get('/api/users', listUsers);
app.post('/api/users', createUser);
app.listen(3000, () => {
console.log('API listening on port 3000');
});Target-specific nodes
These nodes define the structure of an Express API:
server— Application root with name and portroute— HTTP route with method (get, post, put, delete, patch) and pathmiddleware— Named middleware applied globally or per-routehandler— Route handler function referenceschema— Request body and response type annotations for validation
Configuration
Express-specific options in kern.config.ts:
express.security— Security mode:strict(helmet + rate limiting) orrelaxedexpress.helmet— Enablehelmetmiddleware for security headers (default: true in strict)express.compression— Enablecompressionmiddleware (default: false)
import { defineConfig } from '@kernlang/cli';
export default defineConfig({
target: 'express',
outdir: 'src/',
express: {
security: 'strict',
helmet: true,
compression: true,
},
});Quick start
kern dev api.kern --target=express