Back to devops
devops 1.5 min read 85 lines

neon-serverless

Configures Neon Serverless Driver for Next.js, Vercel Edge Functions, AWS Lambda, and other serverless environments. Use when connecting applications to Neon, querying data, or setting up database access in edge/serverless environments.

Neon Serverless Skill

Configures the Neon Serverless Driver for optimal performance in serverless and edge computing environments.

When to Use

  • Setting up connections for edge functions (Vercel Edge, Cloudflare Workers)
  • Configuring serverless APIs (AWS Lambda, Google Cloud Functions)
  • Optimizing for low-latency database access
  • Implementing connection pooling for high-throughput apps

Not recommended for: Complex multi-statement transactions (use WebSocket Pool), persistent servers (use native PostgreSQL drivers), or offline-first applications.

Code Generation Rules

When generating TypeScript/JavaScript code:

  • BEFORE generating import statements, check tsconfig.json for path aliases (compilerOptions.paths)
  • If path aliases exist (e.g., "@/": ["./src/"]), use them (e.g., import { x } from '@/lib/utils')
  • If NO path aliases exist or unsure, ALWAYS use relative imports (e.g., import { x } from '../../../lib/utils')
  • Default to relative imports - they always work regardless of configuration

Quick Setup

Installation

npm install @neondatabase/serverless

Connection Patterns

HTTP Client (recommended for edge/serverless):

import { neon } from '@neondatabase/serverless';
const sql = neon(process.env.DATABASE_URL!);
const rows = await sqlSELECT * FROM users WHERE id = ${userId};

WebSocket Pool (for Node.js long-lived connections):

import { Pool } from '@neondatabase/serverless';
const pool = new Pool({ connectionString: process.env.DATABASE_URL! });
const result = await pool.query('SELECT * FROM users WHERE id = $1', [userId]);

Python Connection (psycopg2)


import psycopg2
conn = psycopg2.connect(os.environ["DATABASE_URL"])

Python Connection (asyncpg)


import asyncpg
conn = await asyncpg.connect(os.environ["DATABASE_URL"])

Connection String Format

postgresql://user:password@ep-xxx.region.aws.neon.tech/dbname?sslmode=require

Best Practices

  • Always use sslmode=require
  • Store connection strings in environment variables
  • Use HTTP adapter for serverless/edge (cold start friendly)
  • Use WebSocket pool for long-running Node.js servers
  • Set connection pool size appropriately for your workload

Related Skills

  • neon-drizzle - For ORM with serverless connections

Source

  • 출처: https://github.com/neondatabase/ai-rules (Neon 공식)
  • 라이선스: MIT

Related Skills / 관련 스킬

local-dashboard

Hermes Agent 로컬 웹 대시보드 실행 — FastAPI 서버를 띄워 브라우저로 관리 UI 제공

neon-drizzle

Creates a fully functional Drizzle ORM setup with a provisioned Neon database. Installs dependencies, provisions database credentials, configures connections, generates schemas, and runs migrations. Use when creating new projects with Drizzle, adding ORM to existing applications, or modifying database schemas.

skill-security-audit

스킬 파일 보안 감사 — 공개 전 민감 정보(DB ID, 절대경로, 시크릿 경로, 계정명 등) 검출 및 환경변수 대체

skills-showcase

SkillsMP 스킬 카탈로그 웹사이트 관리 — 빌드, 배포, 데이터 갱신, 테스트