Express / Node
A complete guide to using Invokix with an Express or Node.js backend. Import your routes directly, keep your contract in sync with your code, and give your frontend team types and hooks the moment your API design is ready.
What Invokix generates for this stack
- TypeScript types for every request and response schema
- Zod validation schemas to use in your route handlers
- A shareable contract link for your frontend and mobile teams
Importing your Express routes
If you already have an Express app, paste your route files into Invokix using the Route Code import. Invokix reads your TypeScript types and Zod schemas and generates a complete OpenAPI contract automatically.
import { Router, Request, Response } from "express"
import { z } from "zod"
const router = Router()
const CreateOrderSchema = z.object({
price: z.number().positive(),
lineItems: z.array(z.object({
productId: z.string(),
quantity: z.number().int().positive(),
price: z.number().positive(),
})).min(1),
})
// GET /orders
router.get("/orders", async (req: Request, res: Response) => {
const orders = await db.orders.findAll()
res.json(orders)
})
// POST /orders
router.post("/orders", async (req: Request, res: Response) => {
const parsed = CreateOrderSchema.safeParse(req.body)
if (!parsed.success) {
return res.status(400).json({ error: "Invalid body" })
}
const order = await db.orders.create(parsed.data)
res.status(201).json(order)
})
export { router as ordersRouter }Using Zod schemas from Invokix in your routes
Pull the generated Zod schemas from Invokix and use them directly in your route handlers. This guarantees your validation always matches your contract.
npx invokix pullimport { CreateOrderBodySchema } from "@/schemas/orders"
router.post("/orders", async (req, res) => {
const parsed = CreateOrderBodySchema.safeParse(req.body)
if (!parsed.success) {
return res.status(400).json({
error: "Invalid request body",
issues: parsed.error.issues,
})
}
const order = await db.orders.create(parsed.data)
res.status(201).json(order)
})Keeping your contract in sync with your code
When you change a route, update the contract in Invokix and publish. Your frontend team gets updated types and hooks immediately. Use the CLI in your development workflow:
# Update contract in Invokix, then pull updated schemas
npx invokix pull
# Your Zod schemas now reflect the updated contract
# TypeScript will catch any mismatches in your route handlers