node-postgres icon indicating copy to clipboard operation
node-postgres copied to clipboard

Improve Deno compatibility: config-first and safe env access

Open Jobians opened this issue 3 months ago • 4 comments

This PR introduces three changes to make the pg package more compatible with Deno while keeping full Node.js functionality:

  1. Default user value

    • Replace user: process.platform === 'win32' ? process.env.USERNAME : process.env.USER
      with user: 'postgres' in defaults.
    • Avoids requiring environment variables in Deno.
  2. Config-first parameter resolution

    • Update val() in connection-parameters.js to return config[key] first, before checking environment variables.
    • Prevents Deno errors when --allow-env is not granted.
  3. Safe NODE_PG_FORCE_NATIVE check

    • Wrap the NODE_PG_FORCE_NATIVE check in a try/catch.
    • Ensures process.env access in Deno doesn’t throw, while preserving Node.js behavior.

These changes maintain Node.js compatibility, preserve the lazy-loading of the native module, and allow using the package in Deno without requiring --allow-env.

Jobians avatar Sep 19 '25 11:09 Jobians