typescript

typescript
import express, { type Express, type Request, type Response } from 'express';

export function buildApp(isShuttingDown: () => boolean): Express {
  const app = express();
  app.disable('x-powered-by');

Graceful shutdown for Node HTTP servers

reliability nodejs express
by codesnips 3 tabs
typescript
export class TimeoutError extends Error {
  constructor(public readonly ms: number) {
    super(`Request timed out after ${ms}ms`);
    this.name = "TimeoutError";
  }
}

HTTP client timeout with AbortController (fetch)

fetch abortcontroller timeout
by codesnips 3 tabs
typescript
import { Link } from 'react-router-dom'
import { useQueryClient } from '@tanstack/react-query'
import api from '@/services/api'
import { PostId } from '@/types'

interface PostLinkProps {

Prefetching data on hover for instant navigation

react performance prefetching
by Maya Patel 1 tab
typescript
import React from 'react'

interface SkeletonProps {
  width?: string | number
  height?: string | number
  className?: string

Skeleton screens for better perceived performance

react ux performance
by Maya Patel 3 tabs
typescript
export interface Post {
  id: string;
  body: string;
  liked: boolean;
  likeCount: number;
}

React Query optimistic update for likes

react typescript frontend
by codesnips 3 tabs
typescript
import { readFileSync } from 'fs';
import { join } from 'path';
import type { Redis } from 'ioredis';
import { randomUUID } from 'crypto';

export interface LimitResult {

Rate limiting by IP + user (Express)

security express redis
by codesnips 4 tabs
typescript
import { Prisma, PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

type TxClient = Prisma.TransactionClient;

Prisma transaction with retries for serialization errors

prisma postgres concurrency
by codesnips 3 tabs
typescript
export interface Page<T> {
  items: T[];
  nextCursor: string | null;
}

export interface Post {

Infinite-Scroll List in React with IntersectionObserver and Cursor Pagination

react hooks infinite-scroll
by codesnips 3 tabs
typescript
import { EventEmitter } from "events";

export interface Job<T> {
  id: string;
  payload: T;
  attempts: number;

Typed In-Memory Job Queue With a Concurrency-Limited Worker Pool

typescript job-queue concurrency
by codesnips 3 tabs
typescript
import { Injectable, NestMiddleware, UnauthorizedException } from '@nestjs/common';
import { Request, Response, NextFunction } from 'express';
import { TenantService } from './tenant.service';

@Injectable()
export class TenantContextMiddleware implements NestMiddleware {

Bind Tenant Context Per Request in NestJS With a Custom @TenantId() Decorator

nestjs multi-tenancy decorators
by codesnips 4 tabs
typescript
import { z } from 'zod';

export const createUserSchema = z
  .object({
    email: z.string().email(),
    name: z.string().min(1).max(120),

Runtime validation for request bodies (Zod)

typescript validation api
by codesnips 3 tabs
typescript
import { NextRequestWithAuth } from 'next/server';
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
import { verifySession } from './lib/verify-session';
import { isProtected, isAuthPage } from './lib/route-matchers';

Next.js middleware for auth gating

nextjs auth security
by codesnips 3 tabs