用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/tools-only/X-Skills --skill express-api-scaffold命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
Index of Build Systems Skills
Coordination patterns for distributed dataflow systems including barriers, epochs, and distributed snapshots
Windowing, sessionization, time-series aggregation, and late data handling for streaming systems
基于 SOC 职业分类
正在显示 SKILL.md
| name | express-api-scaffold |
| description | Generate production-ready Express.js REST API with TypeScript and auth |
| shortcut | eas |
| category | backend |
| difficulty | intermediate |
| estimated_time | 5-10 minutes |
Generates a complete Express.js REST API boilerplate with TypeScript, authentication, database integration, and testing setup.
Generated Project:
Output: Complete API project ready for development
Time: 5-10 minutes
# Generate full Express API
/express-api-scaffold "Task Management API"
# Shortcut
/eas "E-commerce API"
# With specific database
/eas "Blog API" --database postgresql
# With authentication type
/eas "Social API" --auth jwt --database mongodb
Input:
/eas "Task Management API" --database postgresql
Generated Project Structure:
task-api/
├── src/
│ ├── controllers/ # Request handlers
│ │ ├── auth.controller.ts
│ │ └── task.controller.ts
│ ├── middleware/ # Express middleware
│ │ ├── auth.middleware.ts
│ │ ├── error.middleware.ts
│ │ └── validation.middleware.ts
│ ├── models/ # Database models
│ │ └── task.model.ts
│ ├── routes/ # API routes
│ │ ├── auth.routes.ts
│ │ └── task.routes.ts
│ ├── services/ # Business logic
│ │ ├── auth.service.ts
│ │ └── task.service.ts
│ ├── utils/ # Utilities
│ │ ├── jwt.util.ts
│ │ └── password.util.ts
│ ├── config/ # Configuration
│ │ └── database.ts
│ ├── types/ # TypeScript types
│ │ └── express.d.ts
│ ├── app.ts # Express app setup
│ └── server.ts # Server entry point
├── tests/
│ ├── auth.test.ts
│ └── task.test.ts
├── prisma/
│ └── schema.prisma # Database schema
├── .env.example
├── .gitignore
├── package.json
├── tsconfig.json
├── jest.config.js
├── Dockerfile
├── docker-compose.yml
└── README.md
import app from './app'
import { config } from './config'
const PORT = process.env.PORT || 3000
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`)
console.log(`Environment: ${process.env.NODE_ENV}`)
})
import express, { Application } from 'express'
import cors from 'cors'
import helmet from 'helmet'
import morgan from 'morgan'
import rateLimit from 'express-rate-limit'
import authRoutes from './routes/auth.routes'
import taskRoutes from './routes/task.routes'
import { errorHandler } from './middleware/error.middleware'
import { notFoundHandler } from './middleware/notFound.middleware'
const app: Application = express()
// Security middleware
app.use(helmet())
app.use(cors({
origin: process.env.ALLOWED_ORIGINS?.split(',') || '*',
credentials: true
}))
// Rate limiting
const limiter = rateLimit({
windowMs: 15 * 60 * 1000,
: ,
:
})
app.(, limiter)
app.(express.())
app.(express.({ : }))
(process.. !== ) {
app.(())
}
app.(, {
res.({ : , : ().() })
})
app.(, authRoutes)
app.(, taskRoutes)
app.(notFoundHandler)
app.(errorHandler)
app
import { Request, Response, NextFunction } from 'express'
import { AuthService } from '../services/auth.service'
import { ApiError } from '../utils/ApiError'
const authService = new AuthService()
export class AuthController {
async register(req: Request, res: Response, next: NextFunction) {
try {
const { email, password, name } = req.body
const result = await authService.register({ email, password, name })
res.status(201).json({
data: {
user: result.user,
token: result.token
}
})
} catch (error) {
next(error)
}
}
async login(req: Request, res: Response, : ) {
{
{ email, password } = req.
result = authService.(email, password)
res.({
: {
: result.,
: result.
}
})
} (error) {
(error)
}
}
() {
{
userId = req.!.
user = authService.(userId)
res.({ : user })
} (error) {
(error)
}
}
}
import { Request, Response, NextFunction } from 'express'
import jwt from 'jsonwebtoken'
import { ApiError } from '../utils/ApiError'
interface JwtPayload {
userId: string
email: string
}
declare global {
namespace Express {
interface Request {
user?: {
id: string
email: string
}
}
}
}
export function authenticate(req: Request, res: Response, next: NextFunction) {
try {
const authHeader = req.headers.authorization
if (!authHeader?.startsWith('Bearer ')) {
throw new ApiError(401, 'No token provided')
}
const token = authHeader.()[]
decoded = jwt.(
token,
process..!
)
req. = {
: decoded.,
: decoded.
}
()
} (error) {
(error jwt.) {
( (, ))
} {
(error)
}
}
}
import { Request, Response, NextFunction } from 'express'
import { ApiError } from '../utils/ApiError'
import { ZodError } from 'zod'
export function errorHandler(
err: Error,
req: Request,
res: Response,
next: NextFunction
) {
console.error('Error:', err)
// Handle known API errors
if (err instanceof ApiError) {
return res.status(err.statusCode).json({
error: {
code: err.name,
message: err.message,
...(err.details && { details: err.details })
}
})
}
// Handle validation errors (Zod)
if (err instanceof ZodError) {
return res.status(400).({
: {
: ,
: ,
: err..( ({
: e..(),
: e.
}))
}
})
}
res.().({
: {
: ,
: process.. ===
?
: err.
}
})
}
import { Router } from 'express'
import { TaskController } from '../controllers/task.controller'
import { authenticate } from '../middleware/auth.middleware'
import { validate } from '../middleware/validation.middleware'
import { createTaskSchema, updateTaskSchema } from '../schemas/task.schema'
const router = Router()
const taskController = new TaskController()
// All routes require authentication
router.use(authenticate)
router.get('/', taskController.list)
router.post('/', validate(createTaskSchema), taskController.create)
router.get('/:id', taskController.getById)
router.patch('/:id', validate(updateTaskSchema), taskController.update)
router.delete('/:id', taskController.delete)
export default router
import { PrismaClient } from '@prisma/client'
import { ApiError } from '../utils/ApiError'
const prisma = new PrismaClient()
export class TaskService {
async create(userId: string, data: { title: string; description?: string }) {
return await prisma.task.create({
data: {
...data,
userId
}
})
}
async findAll(userId: string) {
return await prisma.task.findMany({
where: { userId },
orderBy: { createdAt: 'desc' }
})
}
async findById(id: string, userId: string) {
const task = await prisma.task.findUnique({
where: { id }
})
if (!task) {
(, )
}
(task. !== userId) {
(, )
}
task
}
() {
.(id, userId)
prisma..({
: { id },
data
})
}
() {
.(id, userId)
prisma..({
: { id }
})
}
}
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
id String @id @default(uuid())
email String @unique
password String
name String
tasks Task[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@map("users")
}
model Task {
id String @id @default(uuid())
title String
description String?
completed Boolean @default(false)
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([userId])
@@map("tasks")
}
import request from 'supertest'
import app from '../src/app'
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
describe('Task API', () => {
let authToken: string
let userId: string
beforeAll(async () => {
// Create test user and get token
const res = await request(app)
.post('/api/auth/register')
.send({
email: '[email protected]',
password: 'password123',
name: 'Test User'
})
authToken = res.body.data.token
userId = res.body.data.user.id
})
afterAll(async () => {
// Cleanup
await prisma.task.deleteMany({ where: { userId } })
prisma..({ : { : userId } })
prisma.$disconnect()
})
(, {
(, () => {
res = (app)
.()
.(, )
.({
: ,
:
})
(res.).()
(res..).()
(res...).()
})
(, () => {
res = (app)
.()
.({ : })
(res.).()
})
})
(, {
(, () => {
res = (app)
.()
.(, )
(res.).()
(.(res..)).()
})
})
})
{
"name": "task-api",
"version": "1.0.0",
"scripts": {
"dev": "ts-node-dev --respawn --transpile-only src/server.ts",
"build": "tsc",
"start": "node dist/server.js",
"test": "jest --coverage",
"lint": "eslint src/**/*.ts",
"format": "prettier --write \"src/**/*.ts\"",
"db:migrate": "prisma migrate dev",
"db:push": "prisma db push",
"db:generate": "prisma generate"
},
"dependencies": {
"express": "^4.18.2",
Security:
Database:
Testing:
Development:
Production:
1. Install dependencies:
npm install
2. Configure environment:
cp .env.example .env
# Edit .env with your database URL and secrets
3. Run database migrations:
npm run db:migrate
4. Start development server:
npm run dev
5. Run tests:
npm test
/fastapi-scaffold - Generate FastAPI boilerplateBuild production-ready APIs. Ship faster. Scale confidently.