This comprehensive guide provides detailed checklists and best practices for optimizing performance across the Node.js/Express/Prisma/PostgreSQL stack with Yarn workspaces.
Provides comprehensive performance optimization checklists for Node.js/Express/Prisma/PostgreSQL stacks with Yarn workspaces.
/plugin marketplace add hmcts/.claude/plugin install expressjs-monorepo@hmctsThis comprehensive guide provides detailed checklists and best practices for optimizing performance across the Node.js/Express/Prisma/PostgreSQL stack with Yarn workspaces.
To quickly analyze code for performance issues, provide the specific file or module:
compression middleware
import compression from 'compression';
app.use(compression({ threshold: 1024 })); // Compress responses > 1KB
if (process.env.NODE_ENV !== 'production') {
app.use(morgan('dev'));
}
fs.readFileSync() → ✅ fs.promises.readFile()crypto.pbkdf2Sync() → ✅ crypto.pbkdf2() with promisifyimport { pipeline } from 'stream/promises';
await pipeline(readStream, transformStream, writeStream);
const cache = new Map();
const CACHE_TTL = 60000; // 1 minute
await prisma.user.findMany({
select: { id: true, name: true } // Don't fetch all fields
});
// Cursor-based (recommended)
await prisma.post.findMany({
take: 20,
cursor: { id: lastId },
orderBy: { id: 'asc' }
});
await prisma.user.createMany({
data: users,
skipDuplicates: true
});
const [posts, totalCount] = await prisma.$transaction([
prisma.post.findMany({ take: 10 }),
prisma.post.count()
]);
const users = await prisma.user.findMany({
include: { posts: true } // Avoid separate queries per user
});
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
connectionLimit = 10 // Adjust based on load
}
const prisma = new PrismaClient({
log: process.env.NODE_ENV === 'development' ? ['query'] : []
});
model User {
email String @unique
name String
@@index([name]) // Add index for frequent name searches
}
SELECT schemaname, tablename, indexname, idx_scan
FROM pg_stat_user_indexes
WHERE idx_scan = 0;
CREATE INDEX idx_active_users ON users(email)
WHERE deleted_at IS NULL;
SET statement_timeout = '30s';
{
"workspaces": {
"packages": ["apps/*", "libs/*"],
"nohoist": ["**/react-native", "**/react-native/**"]
}
}
{
"dependencies": {
"@hmcts/auth": "workspace:*"
}
}
yarn dedupeyarn workspaces focus @hmcts/api --production
{
"compilerOptions": {
"incremental": true,
"tsBuildInfoFile": ".tsbuildinfo"
}
}
node --inspect-brk dist/index.js
When analyzing performance issues:
Before merging performance-related changes: