TypeScript Enum for Postgres Error Codes. Version 2.0.1 provides generated TypeScript enums mapping all PostgreSQL error codes to their SQLSTATE values, with zero runtime dependencies. Updated from the PostgreSQL errcodes.txt source. Supports ESM and CommonJS. Ideal for type-safe error handling in Node.js with the 'pg' library, eliminating magic strings.
npm install pg-error-enumNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to import and use the PostgresError enum to handle PostgreSQL unique constraint violations in a TypeScript project.
Upgrade Node.js to ^22.12.0 || >=24.0.0
Check the generated enum for updated constant names; refer to the errcodes.txt mapping.
Compare with error.code from pg, which is a string.
Upgrade to version 2.0.1 for latest codes.
Add "type": "module" to package.json or use dynamic import.
Run: npm install pg-error-enum
Use import { PostgresError } from 'pg-error-enum' and refer to members directly.No dependency data recorded yet.