
Nodejs Express Server
Drop in Express server, JWT login, and PostgreSQL patterns while scaffolding an API backend with an agent.
Overview
nodejs-express-server is an agent skill for the Build phase that supplies Express, JWT auth, and PostgreSQL starter code patterns.
Install
npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill nodejs-express-serverWhat is this skill?
- Basic Express app with JSON middleware, health route, and centralized error handler
- JWT sign-in flow with bcrypt password compare and 24h token expiry
- PostgreSQL integration patterns (Sequelize-style User lookup in login example)
- Copy-paste async route handlers with asyncHandler-style structure
- Environment-driven PORT and JWT_SECRET configuration
- JWT example uses 24h expiresIn
Adoption & trust: 2.7k installs on skills.sh; 250 GitHub stars; 2/3 security scanners passed (skills.sh audits).
What problem does it solve?
You need a working Express API skeleton with login and database hooks but do not want the agent to invent inconsistent middleware and auth from scratch.
Who is it for?
Solo builders prototyping a SaaS or internal API on Node who want agent-generated code to match familiar Express/JWT shapes.
Skip if: Greenfield projects on Fastify, Nest, or serverless-only stacks, or production hardening without additional review skills.
When should I use this skill?
User asks for Express server setup, JWT authentication routes, or PostgreSQL-backed API snippets in Node.
What do I get? / Deliverables
You get paste-ready route and server files aligned to common JWT and PostgreSQL practices to extend into your full backend.
- Express app bootstrap code
- JWT login route handler
- DB-backed auth flow snippets
Recommended Skills
Journey fit
How it compares
Curated code templates—not a full auth framework, ORM migration guide, or DevOps deploy skill.
Common Questions / FAQ
Who is nodejs-express-server for?
Indie developers using coding agents to bootstrap Node/Express REST APIs with JWT login and a SQL database.
When should I use nodejs-express-server?
During Build backend work when scaffolding routes, health checks, error handling, or a first JWT login endpoint against PostgreSQL.
Is nodejs-express-server safe to install?
It is documentation-style prompts with example secrets in env vars—review the Security Audits panel on this page and never paste production JWT_SECRET values from chat.
SKILL.md
READMESKILL.md - Nodejs Express Server
# Authentication with JWT ## Authentication with JWT ```javascript 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 ```javascript 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) ```javascript 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 ```javascript 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 ```javascript 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 ```javascript // 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 middlew