Scaffold Express.js project with structure
✓Works with OpenClaudeYou are a Node.js scaffolding expert. The user wants to create a new Express.js project with a proper directory structure, essential middleware, and a basic routing setup ready for development.
What to check first
- Run
node --versionto ensure Node.js 14+ is installed - Verify npm is available with
npm --version - Choose or create an empty directory for your project
Steps
- Create a new directory and initialize npm with
npm init -y - Install Express and essential middleware:
npm install express dotenv cors body-parser - Create directories:
mkdir src src/routes src/middleware src/controllers - Create
.envfile in root withPORT=3000andNODE_ENV=development - Create
src/middleware/errorHandler.jsfor centralized error handling - Create
src/routes/index.jswith basic route structure - Create
src/app.jsto configure Express app with middleware - Create
server.jsas entry point that imports and starts the app - Update
package.jsonscripts with"start": "node server.js"and"dev": "node --watch server.js"
Code
// server.js
require('dotenv').config();
const app = require('./src/app');
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`);
});
// src/app.js
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const errorHandler = require('./middleware/errorHandler');
const routes = require('./routes');
const app = express();
// Middleware
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// Request logging middleware
app.use((req, res, next) => {
console.log(`${req.method} ${req.path}`);
next();
});
// Routes
app.use('/api', routes);
// Health check endpoint
app.get('/health', (req, res) => {
res.json({ status: 'OK', timestamp: new Date().toISOString() });
});
// 404 handler
app.use((req, res) => {
res.status(404).json({ error: 'Route not found' });
});
// Error handler (must be last)
app.use(errorHandler);
module.exports = app;
// src/middleware/errorHandler.js
module.exports = (err, req, res, next) => {
const status = err.status || 500;
const message = err.message || 'Internal Server Error';
console.error(`[Error] ${status}: ${message}`);
res.status(status).json({
error: {
status,
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 Scaffolding Skills
Other Claude Code skills in the same category — free to download.
Next.js Starter
Scaffold Next.js project with common setup
React Starter
Scaffold React project with Vite
TypeScript Config
Set up TypeScript configuration
ESLint Config
Configure ESLint with custom rules
Prettier Config
Set up Prettier configuration
Monorepo Setup
Set up monorepo with Turborepo/Nx
Jest Config
Configure Jest testing framework
Vitest Config
Configure Vitest testing framework
Want a Scaffolding 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.