mcpField
E
express

express

github.com/partme-aiDevelopment716104 installsUpdated 3w ago
Repository

About express

An Express skill for developers building Node.js HTTP servers and REST APIs. It provides guidance on routing, middleware, validation, error handling, security headers, and production deployment practices.

Key features

  1. 01Express app and middleware setup
  2. 02Route and router organization
  3. 03Async error handling
  4. 04CORS and security headers
  5. 05REST API validation and responses

Use cases

  1. 01Create a Node.js HTTP server
  2. 02Organize REST API endpoints with routers
  3. 03Handle rejected async route handlers
  4. 04Prepare an Express app for production

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/partme-ai/full-stack-skills --skill express

After installing, type/expressin Claude Code to confirm it loaded.

Bundled filesLICENSE.txt

Details

From the project README

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
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
// 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
// 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

Keywords

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

Comments

Markdown supported