Why isn't the API_PORT variable being loaded? Is there something I'm missing?
I'm trying to load an environment variable API_PORT using Deno and the @std/dotenv module, but it’s not being loaded correctly. The variable is undefined when I try to access it with Deno.env.get('API_PORT'). Here’s the code:
Why isn't the
API_PORT
variable being loaded? Is there something I'm missing?9 Replies
How does your env file look like?
I think you have to specify to export to the Deno env
The .env file is located in the root of the project, alongside the deno.json. The api folder contains the Hono-based API project. Here's the structure:
Any idea why the
API_PORT
isn't loading?
Didn´t work too.
load - @std/dotenv - JSR
@std/dotenv on JSR: UNSTABLE: Parsing and loading environment variables from a
.env
fileYou need to specify
{ export: true }
And you might have to specify the path to the .env file, but you need to double check that
Yes, with a specify the envPath this work´s:
const envVar = await load({envPath: "../.env", export: true})
I'm new to Deno and I have a question regarding environment variables. For development, I need to specify the path to my .env file using dotenv to load the environment variables. However, when running in production (inside a Docker container), I assume I don't need to use dotenv since Docker can handle environment variables directly.
Is my understanding correct? Do I need to manage .env files differently for development and production?You can use
--env
flag built-into Deno to load this file
Then you can have exact same command locally as in production
I don't know if Docker supports .env
filesThanks for your attentions guys