Skip to content

feat: avoid accessing process.env at top-level to allow for use within sandboxed runtimes #3560

@NickCrews

Description

@NickCrews

I want to use this library in the slack deno sdk. But, slack hosts your code for you, and runs it in a sandboxed deno runtime. One of the restrictions they place is they disallow access to process.env.

If I pass in my full databaseUrl, then this library wouldn't need to go looking at process.env to find the fallbacks/default.

Can we make it so that we only access process.env when absolutely needed? It looks like we do this in not that many places, most of which look trivial to make lazy: https://github.com/search?q=repo%3Abrianc%2Fnode-postgres%20process.env&type=code

This one call site looks slightly trickier:

if (typeof process.env.NODE_PG_FORCE_NATIVE !== 'undefined') {
module.exports = new PG(require('./native'))
} else {
module.exports = new PG(Client)

Either

  1. we figure out how to wrap this in a try/catch (would require adding deno-specific error handling I think)
  2. make it possible to pass force_native as an explicit config value, and only look it up from process.env if it isn't set explicitly. Then in my app code I could pass it explicitly to avoid the lookup.

Any interest in this? What's the path forward if so? Could you do the PR or would I need to?

Related: neondatabase/serverless#179

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions