🟢

Node.js

Production-ready Node.js snippets for APIs, authentication, file I/O, and more.

20 snippets

Showing 20 of 20 snippets

typescriptintermediate

JWT Verify Middleware

Express middleware that verifies JWT tokens from the Authorization header and attaches the decoded payload to the request.

#jwt#express
typescriptintermediate

In-Memory Rate Limiter for Express

Token bucket rate limiter middleware for Express with configurable window and max requests per IP.

#express#rate-limit
typescriptbeginner

Async Error Handler Wrapper

Higher-order function that wraps async Express route handlers and forwards rejected promises to error middleware.

#express#async
typescriptbeginner

Environment Variable Validator

Validates required environment variables at startup and returns a typed config object or throws with missing keys.

#config#validation
typescriptintermediate

File Upload with Multer

Configure Multer for disk storage with file type validation, size limits, and unique filenames for Express.

#express#upload
typescriptintermediate

HTTP Client with Axios Interceptors

Pre-configured Axios instance with request/response interceptors for auth headers, logging, and retry logic.

#axios#http
typescriptadvanced

Redis Cache Get/Set Helper

Type-safe Redis cache wrapper with automatic JSON serialization, TTL support, and cache-aside pattern.

#redis#cache
typescriptadvanced

Graceful Server Shutdown

Handle SIGTERM and SIGINT signals to drain connections, close database pools, and exit cleanly.

#server#shutdown
typescriptadvanced

Stream File Download

Express handler that streams a file to the client with proper headers, range support, and error handling.

#stream#download
typescriptbeginner

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.

#uuid#crypto
typescriptintermediate

Prisma Find with Relations

Query related records using Prisma ORM include and select for efficient nested data loading.

#prisma#orm
typescriptintermediate

Bull Queue Job Producer & Consumer

Create a job queue with Bull for background processing with retries and concurrency control.

#queue#bull
typescriptbeginner

Express Zod Request Validation

Validate Express request body, params, and query with Zod schemas via reusable middleware.

#express#zod
typescriptbeginner

Nodemailer Send Email with SMTP

Send transactional emails using Nodemailer with SMTP transport, HTML templates, and attachments.

#email#nodemailer
typescriptbeginner

Node.js Cron Job Scheduler

Schedule recurring tasks with node-cron using crontab syntax and timezone support.

#cron#scheduler
typescriptintermediate

WebSocket Server with ws

Create a WebSocket server with connection tracking, heartbeat ping/pong, and typed message handling.

#websocket#realtime
typescriptadvanced

JWT Refresh Token Rotation

Implement secure token rotation with short-lived access tokens and one-time-use refresh tokens.

#jwt#authentication
typescriptbeginner

Bcrypt Password Hash & Verify

Hash and verify passwords with bcrypt using configurable salt rounds and timing-safe comparison.

#bcrypt#password
typescriptintermediate

CSV Parse with Streaming

Parse large CSV files using Node.js streams with row-by-row processing and backpressure handling.

#csv#stream
typescriptintermediate

S3 Presigned URL Generator

Generate secure presigned URLs for S3 upload and download operations with expiry and content type.

#aws#s3