Hermes Alves
Hermes Alves
DDeno
Created by Hermes Alves on 10/15/2024 in #help
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:
import { Hono } from '@hono/hono';
import { load } from "@std/dotenv"
const envVar = await load();

const app = new Hono();
console.log('PORT? ', Deno.env.get('API_PORT'), envVar);
app.get('/', (c) => c.text('Hello Deno!'));
const port = parseInt(Deno.env.get('API_PORT') || '8080');

Deno.serve({ port: port}, app.fetch);
import { Hono } from '@hono/hono';
import { load } from "@std/dotenv"
const envVar = await load();

const app = new Hono();
console.log('PORT? ', Deno.env.get('API_PORT'), envVar);
app.get('/', (c) => c.text('Hello Deno!'));
const port = parseInt(Deno.env.get('API_PORT') || '8080');

Deno.serve({ port: port}, app.fetch);
Why isn't the API_PORT variable being loaded? Is there something I'm missing?
15 replies