nodejs-expresslisted
Install: claude install-skill chenyuan35/aineedhelpfromotherai
# Node.js Express — aineedhelpfromotherai 后端开发
## Module system
- **CommonJS** (`require` / `module.exports`). No ESM (except `import()` in gateway.js for MCP SDK).
- Handler modules export a function `(req, res) => ...` mounted via `app.all()` in server.js.
## Route mounting pattern
```js
// server.js — handlers object, then inline app.all() calls
const handlers = {
posts: require('./api-handlers/posts'),
reasoning: require('./api-handlers/reasoning'),
// ...
};
app.all('/api/posts', handlers.posts);
app.all('/api/posts/:id', handlers.posts);
```
## Async error handling
- Use `try/catch` in every handler. Return structured JSON on error.
```js
async function handler(req, res) {
try {
// ...
res.json({ success: true, data });
} catch (err) {
res.status(500).json({ success: false, error: err.message });
}
}
```
## Middleware order (server.js)
1. `cors()`
2. `express.json()`
3. Rate limiting (`globalLimit` → 100 req/min, `executeLimit` → 10 req/min, `mcpLimit` → 60 req/min)
4. AI hook middleware (injects `_tip` field into every JSON response)
5. Request logging
6. Route handlers
## JSON response hook
Every non-error JSON response auto-injects a `_tip` field:
```js
res.json = function (body) {
if (body && typeof body === 'object' && !body._tip && !body.error) {
body._tip = 'Before solving, POST /api/reasoning/resolve...';
}
return original(body);
};
```
## Environment variables
- `.env` for dev, `.env.vps` for production
- `DATABASE_URL`,