express
БесплатноБез исполняемых скриптовНе проверенExpress is the minimal web framework for Node.js: routes, middleware, a Router for grouping endpoints, and helpers like res.json. Use when a user asks to…
от TerminalSkills★ 221 звезда на GitHubОб этом скилле
Express — minimal web framework for Node.js
Overview
Express wraps Node's HTTP server with a routing table and a chain of middleware functions (req, res, next). The current major version is 5 (5.3.0 at the time of writing, latest on npm, requires Node.js 18+). Version 5 differs from the 4.x code found in most tutorials in ways that break copy-pasted snippets: wildcard route syntax, query-string parsing, async error handling and several removed methods. This skill is written for 5.x and flags the differences.
Express does not validate input, authenticate, or document the API; it relies on middleware packages and your own code for those.
Instructions
Install and start a server
mkdir inventory-api && cd inventory-api
npm init -y
npm install express
npm pkg set type=module
// server.js
import express from 'express';
const app = express();
app.disable('x-powered-by');
app.use(express.json({ limit: '100kb' }));
app.get('/health', (req, res) => res.json({ ok: true }));
const port = Number(process.env.PORT ?? 4000);
const server = app.listen(port, '127.0.0.1', (err) => {
if (err) throw err;
console.log(`listening on http://127.0.0.1:${server.address().port}`);
});
Run it with node server.js. In Express 5 the app.listen callback receives an error argument, so a port already in use (EADDRINUSE) arrives there instead of being thrown elsewhere; port 0 picks a free port. Bind to 127.0.0.1 unless the process must accept outside traffic.
Routes, parameters, query strings
const books = new Map(1, { id: 1, title: 'Dune' }); // in-memory stand-in for a database
const findBook = async (id) => books.get(id);
const save = (data) => {
const book = { id: books.size + 1, title: data.title };
books.set(book.id, book);
return book;
};
app.get('/books/:id', async (req, res) => {
const book = await findBook(Number(req.params.id));
if (!book) {
const err = new Error('Book not found');
err.status = 404;
throw err; // reaches the error middleware in Express 5
}
res.json(book);
});
app.post('/books', (req, res) => {
if (!req.body?.title) return res.status(400).json({ error: 'title required' });
const book = save(req.body);
res.status(201).location(`/books/${book.id}`).json(book);
});
req.body is undefined (not {}) until a body parser matches the request's Content-Type, so guard with req.body?.field. Built-in parsers: express.json(), express.urlencoded() (its extended default is false in 5), express.text(), express.raw().
Route pattern syntax changed in Express 5 (path-to-regexp 8):
| Express 4 | Express 5 |
|---|---|
/files/* |
/files/*splat (req.params.splat is an array of segments) |
/docs/:version? |
/docs{/:version} |
/:id(\\d+) regex in path |
not supported; validate in the handler |
A bare * now throws Missing parameter name at startup. req.query uses the "simple" parser by default, so ?a[b]=1 yields { "a[b]": "1" }; call app.set('query parser', 'extended') to get nested objects { a: { b: "1" } }.
Router and middleware order
Middleware runs in the order it is registered. Register body parsers and auth before the routes that need them, the 404 handler after all routes, and the error handler last.
import { Router } from 'express';
const items = Router();
items.get('/', (req, res) => res.json([]));
items.get('/:sku', (req, res) => res.json({ sku: req.params.sku }));
app.use('/v1/items', requireApiKey, items);
function requireApiKey(req, res, next) {
if (req.get('x-api-key') !== process.env.INVENTORY_API_KEY) {
return res.status(401).json({ error: 'invalid api key' });
}
next();
}
Read the key from the environment variable INVENTORY_API_KEY; never hard-code it.
Error handling
An error handler has exactly four parameters. In Express 5 a rejected promise or a throw inside an async handler is forwarded to it automatically; Express 4 needed try/catch plus next(err) or a wrapper.
app.use((req, res) => res.status(404).json({ error: 'not found' }));
app.use((err, req, res, next) => {
if (res.headersSent) return next(err);
const status = err.status ?? err.statusCode ?? 500;
if (status >= 500) console.error(err);
res.status(status).json({ error: status >= 500 ? 'internal error' : err.message });
});
Malformed JSON makes express.json() raise an error with status 400 whose message is the parser's text; replace it with a fixed message if you do not want to echo parser details.
Static files
app.use('/assets', express.static('public', { maxAge: '1h', dotfiles: 'ignore' }));
Keep secrets and source out of the served directory; express.static serves every file in it.
Removed or changed in Express 5
Confirmed against 5.3.0: req.param() no longer exists; app.del() is gone (use app.delete); res.json(obj, 201) ignores the
Установить express в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл express?
Express is the minimal web framework for Node.js: routes, middleware, a Router for grouping endpoints, and helpers like res.json. Use when a user asks to "build a REST API with Express", "add a route or middleware", "parse JSON bodies", "handle errors in Express", "serve static files", "write a catch-all route", or "upgrade from Express 4 to 5". Targets Express 5, where async handler errors reach the error middleware and route patterns changed.
Как установить скилл express?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл express запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic