express

$npx mdskill add partme-ai/full-stack-skills/express

Guides developers in building Express.js HTTP servers, routing, middleware, and REST APIs for Node.js applications.

  • Helps with creating HTTP servers, setting up routes, implementing middleware, and building REST APIs in Express.js.
  • Integrates with Node.js and common Express middleware like CORS, Helmet, and body parsing libraries.
  • Decides recommendations based on user queries about Express, server setup, routing, or API development needs.
  • Presents results through code examples, step-by-step workflows, and guidance on deployment and error handling.

SKILL.md

.github/skills/expressView on GitHub ↗
---
name: express
description: "Provides comprehensive guidance for Express.js framework including routing, middleware, request handling, error handling, and API development. Use when the user asks about Express, needs to create HTTP servers, set up routes, implement middleware, or build REST APIs."
license: Complete terms in LICENSE.txt
---

## When to use this skill

Use this skill whenever the user wants to:
- Build Node.js HTTP servers with Express routing and middleware
- Configure CORS, body parsing, error handling, and static files
- Create REST APIs with request validation and response formatting
- Set up production-ready Express applications with security headers

## How to use this skill

### Workflow

1. **Create app** — instantiate Express and configure middleware
2. **Define routes** — set up route handlers for each endpoint
3. **Add error handling** — implement error middleware for consistent responses
4. **Deploy** — run behind a reverse proxy with HTTPS

### Quick Start Example

```javascript
const express = require('express');
const cors = require('cors');
const helmet = require('helmet');

const app = express();

// Middleware
app.use(helmet());
app.use(cors());
app.use(express.json());

// Routes
app.get('/api/items', async (req, res, next) => {
  try {
    const items = await Item.findAll();
    res.json({ items });
  } catch (err) {
    next(err);
  }
});

app.post('/api/items', async (req, res, next) => {
  try {
    const { name, price } = req.body;
    const item = await Item.create({ name, price });
    res.status(201).json(item);
  } catch (err) {
    next(err);
  }
});

// 404 handler
app.use((req, res) => {
  res.status(404).json({ error: 'Not found' });
});

// Error middleware (must have 4 params)
app.use((err, req, res, next) => {
  console.error(err.stack);
  res.status(err.status || 500).json({
    error: err.message || 'Internal server error',
  });
});

app.listen(3000, () => console.log('Server running on port 3000'));
```

### Async Error Wrapper

```javascript
// Wrap async handlers to catch rejected promises
const asyncHandler = (fn) => (req, res, next) =>
  Promise.resolve(fn(req, res, next)).catch(next);

app.get('/api/users', asyncHandler(async (req, res) => {
  const users = await User.findAll();
  res.json(users);
}));
```

### Router Example

```javascript
// routes/items.js
const router = require('express').Router();

router.get('/', asyncHandler(async (req, res) => { /* ... */ }));
router.post('/', asyncHandler(async (req, res) => { /* ... */ }));
router.get('/:id', asyncHandler(async (req, res) => { /* ... */ }));

module.exports = router;

// app.js
app.use('/api/items', require('./routes/items'));
```

## Best Practices

- Separate routes and middleware into modules; use `express.Router()` for organization
- Always wrap async handlers with try/catch or a wrapper to avoid unhandled rejections
- Use `helmet` for security headers and configure CORS for production origins
- Deploy behind a reverse proxy (nginx) with HTTPS in production
- Use `morgan` for request logging and structured error responses

## Reference

- Official documentation: https://expressjs.com/

## Keywords

express, Node.js, middleware, routing, REST API, error handling, async, helmet, cors

More from partme-ai/full-stack-skills

SkillDescription
adobe-xd"Guides creation of UI/UX designs, interactive prototypes, reusable components, and design specs in Adobe XD. Use when the user asks about Adobe XD artboards, prototype links, repeat grids, component states, design tokens export, or developer handoff."
angular"Provides comprehensive guidance for Angular framework including components, modules, services, dependency injection, routing, forms, and TypeScript integration. Use when the user asks about Angular, needs to create Angular applications, implement Angular components, or work with Angular features."
ansible"Provides comprehensive guidance for Ansible automation including playbooks, roles, inventory, and module usage. Use when the user asks about Ansible, needs to automate IT tasks, create Ansible playbooks, or manage infrastructure with Ansible."
ant-design-mini"Builds mini-program UIs with Ant Design Mini components for Alipay and WeChat mini-programs. Covers Button, Form, List, Modal, Tabs, NavBar, and 60+ components with theme customization and CSS variable theming. Use when the user needs to create mini-program interfaces with Ant Design Mini, configure themes, or implement mini-program-specific UI patterns."
ant-design-mobile"Builds React mobile UIs with Ant Design Mobile (antd-mobile) components including Button, Form, List, Modal, Picker, Tabs, PullToRefresh, InfiniteScroll, and 50+ mobile-optimized components. Use when the user needs to create mobile-first React interfaces, implement mobile navigation, forms, or data display with Ant Design Mobile."
ant-design-react"Builds enterprise React UIs with Ant Design (antd) including 60+ components (Button, Form, Table, Select, Modal, Message), design tokens, TypeScript support, and ConfigProvider theming. Use when the user needs to create React applications with Ant Design, build forms with validation, display data tables, or customize the Ant Design theme."
ant-design-vueProvides comprehensive guidance for Ant Design Vue (AntDV) component library for Vue 3. Covers installation, usage, API reference, templates, and all component categories. Use when building enterprise-class UI with Vue 3 and Ant Design.
api-doc-generator"Generate API documentation by scanning Controller classes, extracting endpoint URLs, HTTP methods, parameters, and response structures, then producing standardized docs from templates. Use when the user explicitly mentions generating API documentation, creating API docs, scanning interfaces, or documenting REST APIs. Do not trigger for generic documentation requests without explicit API mention."
appium"Provides comprehensive guidance for Appium mobile testing including mobile app automation, element location, gestures, and cross-platform testing. Use when the user asks about Appium, needs to test mobile applications, automate mobile apps, or write Appium test scripts."
ascii-ansi-colorizer"Add an ANSI color layer to existing ASCII/plain-text output (gradient/rainbow/highlights) with alignment-safe rules and a required no-color fallback. Use when the user wants to colorize terminal output, add rainbow effects to CLI text, or style ASCII art with ANSI colors."