Nezir
Nezir

Reputation: 6915

Deno.env is not a function

Working on short tutorial with deno and postgres from https://blog.logrocket.com/creating-your-first-rest-api-with-deno-and-postgres/

I had an error within my config.js file:

const env = Deno.env();

export const APP_HOST = env.APP_HOST || "127.0.0.1";
export const APP_PORT = env.APP_PORT || 4000;

Running deno command I got the error:

$ deno run -A index.js
error: Uncaught TypeError: Deno.env is not a function
const env = Deno.env();

Upvotes: 1

Views: 1309

Answers (2)

Marcos Casagrande
Marcos Casagrande

Reputation: 40414

That blog post is using an older version of Deno, where Deno.env() was a function.

It was changed for 1.0.0 release. Deno.env is now an object with: .set , .get, .toObject methods.

So to get an env variable you do:

Deno.env.get('MY_VARIABLE');

Deno introduced a lot of breaking changes for 1.0.0 release, so I suggest to avoid using code from tutorials using <1.0.0.

Upvotes: 3

T.J. Crowder
T.J. Crowder

Reputation: 1074525

As the error says, Deno.env isn't a function. So you don't use () on it. It's an object, you use it directly:

const env = Deno.env;

Upvotes: 0

Related Questions