express-typescript — Claude Code skill: Express.js and TypeScript APIs
Rules that steer your agent when it writes Express.js and TypeScript APIs: project layout, middleware, validation, security.
npx skills add Mindrally/skills --skill express-typescript -a claude-codeWhat express-typescript does
This skill hands the agent a set of conventions for Express.js and TypeScript code. Naming rules come first: PascalCase for types, camelCase for functions, kebab-case for files. No any — build the type instead. Interfaces over type aliases, Zod for runtime validation. The agent also gets a directory layout to follow: routes/{resource}/ with controller and validators, plus middleware/, services/, models/, types/express.d.ts.
Then come the code patterns. App setup with helmet, cors and body parsing. A request logger that times each call. Auth middleware that pulls the token from the authorization header. A router where validation runs before the controller and the error handler sits last in the chain. There is a section on extending Express types with declare global so req.user stops failing type checks.
Security is a checklist: security headers, rate limiting, input sanitisation, HTTPS in production. The rate limiter example in the source cuts off partway through its options, so you pick the window and the request cap yourself. The skill installs across six platforms, and the rule text is the same everywhere — no drift between editors.
What it helps with
- split Express routes by resource with controllers and validators
- write auth middleware that verifies a bearer token
- wire up Zod and return 400 with error details
- build a central error handler with AppError classes
- add helmet, CORS and request rate limiting to the app
Example prompts for the agent
- Set up an Express TypeScript project structure using the express-typescript skill
- Add Zod validation middleware for the create user route
- Show me how to extend the Request type with a user field
How to install express-typescript
1Skills CLI (Vercel)
npx skills add Mindrally/skills --skill express-typescript -a claude-code2Manually: put the files in place
~/.claude/skills/express-typescript/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/express-typescript/
1Skills CLI (Vercel)
npx skills add Mindrally/skills --skill express-typescript -a codex2Manually: put the files in place
.agents/skills/express-typescript/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add Mindrally/skills --skill express-typescript -a cursor2Manually: put the files in place
.cursor/skills/express-typescript/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install Mindrally/skills express-typescript2Manually: put the files in place
.github/skills/express-typescript/SKILL.md1Skills CLI (Vercel)
npx skills add Mindrally/skills --skill express-typescript -a gemini-cli2Platform CLI
gemini skills install https://github.com/Mindrally/skills --path express-typescriptManually: put the files in place
.devin/skills/express-typescript/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add Mindrally/skills --skill express-typescript -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about express-typescript
How do I install express-typescript in Claude?
Run npx skills add Mindrally/skills --skill express-typescript -a claude-code. The skill file lands in ~/.claude/skills/express-typescript/SKILL.md.
What does express-typescript do?
It gives the agent conventions for building Express.js and TypeScript APIs: directory layout, middleware patterns, request validation and security practices.
Which platforms support the skill?
Claude, Codex, Cursor, GitHub Copilot, Gemini CLI and OpenCode. Each platform has its own install command and skill file path.
Source text
SKILL.md · Apache-2.0
---
name: express-typescript
description: Guidelines for building robust APIs with Express.js and TypeScript, covering middleware patterns, routing, and security best practices
metadata:
maintainer: Mindrally
source: https://github.com/Mindrally/skills
---
# Express TypeScript Development
You are an expert in Express.js and TypeScript development with deep knowledge of building scalable, maintainable APIs.
## TypeScript General Guidelines
### Basic Principles
- Use English for all code and documentation
- Always declare types for variables and functions (parameters and return values)
- Avoid using `any` type - create necessary types instead
- Use JSDoc to document public classes and methods
- Write concise, maintainable, and technically accurate code
- Use functional and declarative programming patterns; avoid classes where possible
- Prefer iteration and modularization to adhere to DRY principles
### Nomenclature
- Use PascalCase for types and interfaces
- Use camelCase for variables, functions, and methods
- Use kebab-case for file and directory names
- Use UPPERCASE for environment variables
- Use descriptive variable names with auxiliary verbs: `isLoading`, `hasError`, `canDelete`
- Start each function with a verb
### Functions
- Write short functions with a single purpose
- Use arrow functions for middleware and handlers
- Use async/await consistently throughout the codebase
- Use the RO-RO pattern for multiple parameters
### Types and Interfaces
- Prefer interfaces over types for object shapes
- Avoid enums; use maps or const objects instead
- Use Zod for runtime validation with inferred types
- Use `readonly` for immutable properties
## Express-Specific Guidelines
### Project Structure
```
src/
routes/
{resource}/
index.ts
controller.ts
validators.ts
middleware/
auth.ts
errorHandler.ts
requestLogger.ts
validateRequest.ts
services/
{domain}Service.ts
models/
{entity}.ts
types/
express.d.ts
index.ts
utils/
config/
app.ts
server.ts
```
### Application Setup
```typescript
import express, { Express } from 'express';
import helmet from 'helmet';
import cors from 'cors';
import { errorHandler } from './middleware/errorHandler';
import { requestLogger } from './middleware/requestLogger';
import routes from './routes';
const createApp = (): Express => {
const app = express();
// Security middleware
app.use(helmet());
app.use(cors());
// Body parsing
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// Request logging
app.use(requestLogger);
// Routes
app.use('/api', routes);
// Error handling (must be last)
app.use(errorHandler);
return app;
};
export default createApp;
```
### Middleware Patterns
- Use middleware for cross-cutting concerns
- Chain middleware in order of execution
- Handle errors in dedicated error middleware
```typescript
import { Request, Response, NextFunction } from 'express';
// Request logging middleware
const requestLogger = (req: Request, res: Response, next: NextFunction): void => {
const start = Date.now();
res.on('finish', () => {
const duration = Date.now() - start;
console.log(`${req.method} ${req.path} ${res.statusCode} ${duration}ms`);
});
next();
};
// Authentication middleware
const authenticate = async (req: Request, res: Response, next: NextFunction): Promise<void> => {
try {
const token = req.headers.authorization?.split(' ')[1];
if (!token) {
res.status(401).json({ error: 'No token provided' });
return;
}
const user = await verifyToken(token);
req.user = user;
next();
} catch (error) {
res.status(401).json({ error: 'Invalid token' });
}
};
```
### Routing
- Organize routes by resource
- Use Router for modular route definitions
- Apply middleware at appropriate levels
```typescript
import { Router } from 'express';
import { authenticate } from '../middleware/auth';
import { validateRequest } from '../middleware/validateRequest';
import { createUserSchema, updateUserSchema } from './validators';
import * as controller from './controller';
const router = Router();
router.get('/', controller.listUsers);
router.get('/:id', controller.getUser);
router.post('/', validateRequest(createUserSchema), controller.createUser);
router.put('/:id', authenticate, validateRequest(updateUserSchema), controller.updateUser);
router.delete('/:id', authenticate, controller.deleteUser);
export default router;
```
### Request Validation
- Validate all incoming requests
- Use Zod for schema definition and validation
- Create reusable validation middleware
```typescript
import { z } from 'zod';
import { Request, Response, NextFunction } from 'express';
const createUserSchema = z.object({
body: z.object({
name: z.string().min(1),
email: z.string().email(),
password: z.string().min(8),
}),
});
const validateRequest = (schema: z.ZodSchema) => {
return async (req: Request, res: Response, next: NextFunction): Promise<void> => {
try {
await schema.parseAsync({
body: req.body,
query: req.query,
params: req.params,
});
next();
} catch (error) {
if (error instanceof z.ZodError) {
res.status(400).json({
error: 'Validation failed',
details: error.errors,
});
return;
}
next(error);
}
};
};
```
### Error Handling
- Create custom error classes
- Use centralized error handler middleware
- Return consistent error responses
```typescript
class AppError extends Error {
constructor(
public statusCode: number,
public message: string,
public code: string = 'INTERNAL_ERROR'
) {
super(message);
this.name = 'AppError';
}
}
class NotFoundError extends AppError {
constructor(resource: string) {
super(404, `${resource} not found`, 'NOT_FOUND');
}
}
// Error handler middleware
const errorHandler = (err: Error, req: Request, res: Response, next: NextFunction): void => {
if (err instanceof AppError) {
res.status(err.statusCode).json({
error: err.code,
message: err.message,
});
return;
}
console.error(err);
res.status(500).json({
error: 'INTERNAL_ERROR',
message: 'An unexpected error occurred',
});
};
```
### TypeScript Extensions
Extend Express types for custom properties:
```typescript
// types/express.d.ts
import { User } from '../models/User';
declare global {
namespace Express {
interface Request {
user?: User;
requestId?: string;
}
}
}
```
### Security Best Practices
- Use helmet for security headers
- Implement rate limiting
- Sanitize user inputs
- Use HTTPS in production
- Implement CORS properly
```typescript
import helmet from 'helmet';
import rateLimit from 'express-rate-limit';
app.use(helmet());
const limiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // limit each IP to 100 requests per windowMs
});
app.use('/api', limiter);
```
### Testing
- Use Jest with supertest for integration tests
- Test middleware in isolation
- Mock external dependencies
```typescript
import request from 'supertest';
import createApp from '../app';
describe('Users API', () => {
const app = createApp();
it('should create a user', async () => {
const response = await request(app)
.post('/api/users')
.send({ name: 'John', email: '[email protected]', password: 'password123' })
.expect(201);
expect(response.body).toHaveProperty('id');
expect(response.body.name).toBe('John');
});
});
```
© Mindrally · Apache-2.0 · Mindrally/skills