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 port
- route — HTTP route with method (get, post, put, delete, patch) and path
- middleware — Named middleware applied globally or per-route
- handler — Route handler function reference
- schema — Request body and response type annotations for validation
Configuration
Express-specific options in kern.config.ts:
- express.security — Security mode: strict (helmet + rate limiting) or relaxed
- express.helmet — Enable helmet middleware for security headers (default: true in strict)
- express.compression — Enable compression middleware (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