
Nodejs Express Server
- 3k installs
- 305 repo stars
- Updated March 4, 2026
- aj-geddes/useful-ai-prompts
nodejs-express-server is an agent skill that guides production Express.js REST API setup with middleware chains, JWT authentication, Sequelize PostgreSQL integration, and structured error handling.
About
The nodejs-express-server skill documents how to build production-ready Express.js servers with routing, middleware chains, authentication, database integration, and centralized error handling. It opens with a minimal working server using express.json and express.urlencoded middleware, a /health route, and error middleware that returns JSON with requestId and status codes. Reference guides in references/ cover basic Express setup, middleware chain implementation, PostgreSQL integration with Sequelize, JWT authentication, RESTful CRUD routes, error-handling middleware, and environment configuration. Documented best practices include async await in route handlers, input validation before processing, rate limiting, HTTPS in production, logging, and keeping route handlers small. Anti-patterns warn against silent errors, storing secrets in code, synchronous route work, callback hell, exposing stack traces, and trusting client-side validation alone. Developers reach for it when creating REST APIs, wiring cross-cutting middleware, protecting routes with JWT, or connecting Express to PostgreSQL through Sequelize.
- Minimal Express template with JSON body parsing, health route, and centralized JSON error middleware.
- Reference guides for Sequelize PostgreSQL, JWT auth, CRUD routes, and environment configuration.
- Best practices cover async await routes, input validation, rate limiting, and HTTPS in production.
- Anti-patterns flag silent errors, secrets in code, callback hell, and exposed stack traces.
- Structured references/ directory splits middleware, database, auth, and error topics into focused guides.
Nodejs Express Server by the numbers
- 3,041 all-time installs (skills.sh)
- +35 installs in the week ending Aug 4, 2026 (Skillselion tracking)
- Ranked #189 of 4,347 Backend & APIs skills by installs in the Skillselion catalog
- Security screen: HIGH risk (skills.sh audit)
- Data as of Aug 5, 2026 (Skillselion catalog sync)
nodejs-express-server capabilities & compatibility
- Capabilities
- express middleware chain patterns · jwt authentication route protection · sequelize postgresql database integration · restful crud route templates · centralized json error handling
- Use cases
- api development · database
What nodejs-express-server says it does
Build production-ready Express.js servers with middleware, authentication, routing, and database integration.
Use middleware for cross-cutting concerns
Database Integration (PostgreSQL with Sequelize)
npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill nodejs-express-serverAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 3k |
|---|---|
| repo stars | ★ 305 |
| Security audit | 2 / 3 scanners passed |
| Last updated | March 4, 2026 |
| Repository | aj-geddes/useful-ai-prompts ↗ |
How do I structure an Express.js REST API with middleware, JWT auth, database integration, and safe error responses?
Scaffold production Express.js REST APIs with middleware chains, JWT auth, Sequelize PostgreSQL integration, and structured error handling.
Who is it for?
Developers standing up Node.js REST APIs who need middleware, JWT auth, and PostgreSQL Sequelize integration patterns.
Skip if: Skip when you need a non-Express Node framework or only client-side JavaScript without a server.
When should I use this skill?
User asks to build Express REST APIs, implement JWT middleware, connect Sequelize PostgreSQL, or structure error-handling middleware.
What you get
A production-oriented Express server layout with reference guides for middleware, Sequelize, JWT routes, and error handling patterns.
- Express server template
- Middleware and auth reference patterns
By the numbers
- JWT tokens expire in 24h per included generateToken implementation
- Covers jsonwebtoken, bcrypt, and PostgreSQL User model patterns
Files
Node.js Express Server
Table of Contents
Overview
Create robust Express.js applications with proper routing, middleware chains, authentication mechanisms, and database integration following industry best practices.
When to Use
- Building REST APIs with Node.js
- Implementing server-side request handling
- Creating middleware chains for cross-cutting concerns
- Managing authentication and authorization
- Connecting to databases from Node.js
- Implementing error handling and logging
Quick Start
Minimal working example:
const express = require("express");
const app = express();
const PORT = process.env.PORT || 3000;
// Middleware
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// Routes
app.get("/health", (req, res) => {
res.json({ status: "OK", timestamp: new Date().toISOString() });
});
// Error handling
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(err.status || 500).json({
error: err.message,
requestId: req.id,
});
});
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});Reference Guides
Detailed implementations in the references/ directory:
| Guide | Contents |
|---|---|
| Basic Express Setup | Basic Express Setup |
| Middleware Chain Implementation | Middleware Chain Implementation |
| Database Integration (PostgreSQL with Sequelize) | Database Integration (PostgreSQL with Sequelize) |
| Authentication with JWT | Authentication with JWT |
| RESTful Routes with CRUD Operations | RESTful Routes with CRUD Operations |
| Error Handling Middleware | Error Handling Middleware |
| Environment Configuration | Environment Configuration |
Best Practices
✅ DO
- Use middleware for cross-cutting concerns
- Implement proper error handling
- Validate input data before processing
- Use async/await for async operations
- Implement authentication on protected routes
- Use environment variables for configuration
- Add logging and monitoring
- Use HTTPS in production
- Implement rate limiting
- Keep route handlers focused and small
❌ DON'T
- Handle errors silently
- Store sensitive data in code
- Use synchronous operations in routes
- Forget to validate user input
- Implement authentication in route handlers
- Use callback hell (use promises/async-await)
- Expose stack traces in production
- Trust client-side validation only
Authentication with JWT
Authentication with JWT
const jwt = require("jsonwebtoken");
const bcrypt = require("bcrypt");
const generateToken = (userId) => {
return jwt.sign(
{ userId, iat: Math.floor(Date.now() / 1000) },
process.env.JWT_SECRET,
{ expiresIn: "24h" },
);
};
app.post(
"/login",
asyncHandler(async (req, res) => {
const { email, password } = req.body;
const user = await User.findOne({ where: { email } });
if (!user) return res.status(404).json({ error: "User not found" });
const validPassword = await bcrypt.compare(password, user.password);
if (!validPassword)
return res.status(401).json({ error: "Invalid password" });
const token = generateToken(user.id);
res.json({ token, user: { id: user.id, email: user.email } });
}),
);Basic Express Setup
Basic Express Setup
const express = require("express");
const app = express();
const PORT = process.env.PORT || 3000;
// Middleware
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// Routes
app.get("/health", (req, res) => {
res.json({ status: "OK", timestamp: new Date().toISOString() });
});
// Error handling
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(err.status || 500).json({
error: err.message,
requestId: req.id,
});
});
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});Database Integration (PostgreSQL with Sequelize)
Database Integration (PostgreSQL with Sequelize)
const { Sequelize, DataTypes } = require("sequelize");
const sequelize = new Sequelize(
process.env.DB_NAME,
process.env.DB_USER,
process.env.DB_PASS,
{
host: process.env.DB_HOST,
dialect: "postgres",
logging: false,
},
);
const User = sequelize.define(
"User",
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
email: {
type: DataTypes.STRING,
unique: true,
allowNull: false,
},
password: DataTypes.STRING,
role: {
type: DataTypes.ENUM("user", "admin"),
defaultValue: "user",
},
},
{
timestamps: true,
},
);
// Sync database
sequelize.sync({ alter: true });Environment Configuration
Environment Configuration
require("dotenv").config();
const config = {
port: process.env.PORT || 3000,
env: process.env.NODE_ENV || "development",
database: {
url: process.env.DATABASE_URL,
dialect: "postgres",
},
jwt: {
secret: process.env.JWT_SECRET,
expiresIn: "24h",
},
cors: {
origin: process.env.CORS_ORIGIN || "http://localhost:3000",
},
};
module.exports = config;Error Handling Middleware
Error Handling Middleware
class AppError extends Error {
constructor(message, statusCode) {
super(message);
this.statusCode = statusCode;
Error.captureStackTrace(this, this.constructor);
}
}
app.use((err, req, res, next) => {
err.statusCode = err.statusCode || 500;
if (err.name === "SequelizeValidationError") {
return res.status(400).json({
error: "Validation failed",
details: err.errors.map((e) => ({ field: e.path, message: e.message })),
});
}
if (process.env.NODE_ENV === "production") {
return res.status(err.statusCode).json({
error: err.message,
requestId: req.id,
});
}
res.status(err.statusCode).json({
error: err.message,
stack: err.stack,
});
});
app.use((req, res) => {
res.status(404).json({ error: "Route not found" });
});Middleware Chain Implementation
Middleware Chain Implementation
// Logging middleware
const logger = (req, res, next) => {
const start = Date.now();
res.on("finish", () => {
const duration = Date.now() - start;
console.log(`${req.method} ${req.path} ${res.statusCode} ${duration}ms`);
});
next();
};
// Authentication middleware
const authenticateToken = (req, res, next) => {
const token = req.headers["authorization"]?.split(" ")[1];
if (!token) return res.status(401).json({ error: "No token" });
jwt.verify(token, process.env.JWT_SECRET, (err, user) => {
if (err) return res.status(403).json({ error: "Invalid token" });
req.user = user;
next();
});
};
// Error catching middleware wrapper
const asyncHandler = (fn) => (req, res, next) => {
Promise.resolve(fn(req, res, next)).catch(next);
};
app.use(logger);
app.use(express.json());
app.get("/protected", authenticateToken, (req, res) => {
res.json({ user: req.user });
});RESTful Routes with CRUD Operations
RESTful Routes with CRUD Operations
const userRouter = express.Router();
// GET all users (with pagination)
userRouter.get(
"/",
authenticateToken,
asyncHandler(async (req, res) => {
const { page = 1, limit = 20 } = req.query;
const users = await User.findAndCountAll({
offset: (page - 1) * limit,
limit: parseInt(limit),
});
res.json({
data: users.rows,
pagination: { page, limit, total: users.count },
});
}),
);
// GET single user
userRouter.get(
"/:id",
authenticateToken,
asyncHandler(async (req, res) => {
const user = await User.findByPk(req.params.id);
if (!user) return res.status(404).json({ error: "Not found" });
res.json({ data: user });
}),
);
// POST create user
userRouter.post(
"/",
asyncHandler(async (req, res) => {
const { email, password } = req.body;
const hashedPassword = await bcrypt.hash(password, 10);
const user = await User.create({
email,
password: hashedPassword,
});
res.status(201).json({ data: user });
}),
);
// PATCH update user
userRouter.patch(
"/:id",
authenticateToken,
asyncHandler(async (req, res) => {
const user = await User.findByPk(req.params.id);
if (!user) return res.status(404).json({ error: "Not found" });
await user.update(req.body, {
fields: ["email", "role"],
});
res.json({ data: user });
}),
);
// DELETE user
userRouter.delete(
"/:id",
authenticateToken,
asyncHandler(async (req, res) => {
const user = await User.findByPk(req.params.id);
if (!user) return res.status(404).json({ error: "Not found" });
await user.destroy();
res.status(204).send();
}),
);
app.use("/api/users", userRouter);#!/bin/bash
# security-checklist.sh - Generate a security review checklist
# Usage: ./security-checklist.sh [--output checklist.md]
set -euo pipefail
OUTPUT="${{1:-/dev/stdout}}"
cat > "$OUTPUT" << 'CHECKLIST'
# Security Review Checklist
## Authentication & Authorization
- [ ] All endpoints require authentication
- [ ] Role-based access control implemented
- [ ] Session management is secure
## Input Validation
- [ ] All user inputs are validated
- [ ] SQL injection prevention
- [ ] XSS prevention
## Data Protection
- [ ] Sensitive data encrypted at rest
- [ ] Sensitive data encrypted in transit
- [ ] PII handling compliant
## TODO: Add domain-specific security checks
CHECKLIST
echo "Checklist generated: $OUTPUT" >&2
Related skills
How it compares
Express API reference pack with Sequelize and JWT guides, not a generic Node tutorial.
FAQ
What does nodejs-express-server cover?
Express routing, middleware chains, JWT authentication, Sequelize PostgreSQL integration, CRUD routes, and error-handling middleware.
When should I use nodejs-express-server?
When building REST APIs, managing request handling, implementing middleware, or connecting Express to a database.
Is Nodejs Express Server safe to install?
skills.sh reports 2 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.