Scaffold Express.js app with best practices
✓Works with OpenClaudeYou are a Node.js backend developer. The user wants to scaffold a production-ready Express.js application with current best practices.
What to check first
- Run
node --versionto ensure Node.js 16+ is installed - Verify
npm --versionoryarn --versionis available - Check that the target directory is empty or create a new folder with
mkdir my-express-app && cd my-express-app
Steps
- Initialize the project with
npm init -yto generate package.json - Install core Express dependencies:
npm install express dotenv cors helmet morgan - Install dev dependencies for development:
npm install --save-dev nodemon @types/node - Create the directory structure:
mkdir -p src/routes src/middleware src/config - Create
.envfile in root withPORT=3000andNODE_ENV=development - Create
.gitignorefile and addnode_modules/,.env,.DS_Store - Set up
package.jsonscripts with"start": "node src/index.js"and"dev": "nodemon src/index.js" - Create
src/index.jswith Express server initialization, middleware setup, and error handling - Create a basic route file in
src/routes/health.jsfor health checks - Add
src/middleware/errorHandler.jsfor centralized error handling
Code
// src/index.js
const express = require('express');
const cors = require('cors');
const helmet = require('helmet');
const morgan = require('morgan');
require('dotenv').config();
const app = express();
const PORT = process.env.PORT || 3000;
const NODE_ENV = process.env.NODE_ENV || 'development';
// Security middleware
app.use(helmet());
app.use(cors({
origin: process.env.CORS_ORIGIN || '*',
credentials: true,
}));
// Logging middleware
app.use(morgan(NODE_ENV === 'development' ? 'dev' : 'combined'));
// Body parsing middleware
app.use(express.json({ limit: '10mb' }));
app.use(express.urlencoded({ limit: '10mb', extended: true }));
// Health check route
app.get('/health', (req, res) => {
res.json({
status: 'ok',
timestamp: new Date().toISOString(),
environment: NODE_ENV,
});
});
// 404 handler
app.use((req, res) => {
res.status(404).json({
error: 'Route not found',
path: req.path,
method: req.method,
});
});
// Error handling middleware (must be last)
app.use((err, req, res, next) => {
const status = err.status || 500;
const message =
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Backend Skills
Other Claude Code skills in the same category — free to download.
Fastify Setup
Scaffold Fastify app with plugins
NestJS Module
Generate NestJS modules, controllers, services
Middleware Chain
Create and organize middleware chain
Queue Worker
Set up job queue with Bull/BullMQ
File Upload Handler
Create file upload handling with validation
Email Service
Set up transactional email service
WebSocket Setup
Implement WebSocket server with rooms
Cron Job Setup
Set up scheduled cron jobs
Want a Backend skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.