Node.js
Production-ready Node.js snippets for APIs, authentication, file I/O, and more.
20 snippets
Showing 20 of 20 snippets
JWT Verify Middleware
Express middleware that verifies JWT tokens from the Authorization header and attaches the decoded payload to the request.
In-Memory Rate Limiter for Express
Token bucket rate limiter middleware for Express with configurable window and max requests per IP.
Async Error Handler Wrapper
Higher-order function that wraps async Express route handlers and forwards rejected promises to error middleware.
Environment Variable Validator
Validates required environment variables at startup and returns a typed config object or throws with missing keys.
File Upload with Multer
Configure Multer for disk storage with file type validation, size limits, and unique filenames for Express.
HTTP Client with Axios Interceptors
Pre-configured Axios instance with request/response interceptors for auth headers, logging, and retry logic.
Redis Cache Get/Set Helper
Type-safe Redis cache wrapper with automatic JSON serialization, TTL support, and cache-aside pattern.
Graceful Server Shutdown
Handle SIGTERM and SIGINT signals to drain connections, close database pools, and exit cleanly.
Stream File Download
Express handler that streams a file to the client with proper headers, range support, and error handling.
UUID and Nano ID Generator
Generate RFC-4122 v4 UUIDs and URL-safe nano IDs using the Node.js built-in crypto module with zero deps.
Prisma Find with Relations
Query related records using Prisma ORM include and select for efficient nested data loading.
Bull Queue Job Producer & Consumer
Create a job queue with Bull for background processing with retries and concurrency control.
Express Zod Request Validation
Validate Express request body, params, and query with Zod schemas via reusable middleware.
Nodemailer Send Email with SMTP
Send transactional emails using Nodemailer with SMTP transport, HTML templates, and attachments.
Node.js Cron Job Scheduler
Schedule recurring tasks with node-cron using crontab syntax and timezone support.
WebSocket Server with ws
Create a WebSocket server with connection tracking, heartbeat ping/pong, and typed message handling.
JWT Refresh Token Rotation
Implement secure token rotation with short-lived access tokens and one-time-use refresh tokens.
Bcrypt Password Hash & Verify
Hash and verify passwords with bcrypt using configurable salt rounds and timing-safe comparison.
CSV Parse with Streaming
Parse large CSV files using Node.js streams with row-by-row processing and backpressure handling.
S3 Presigned URL Generator
Generate secure presigned URLs for S3 upload and download operations with expiry and content type.