DenoDDeno
Powered by
Hermes AlvesH
Deno•2y ago•
14 replies
Hermes Alves

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
API_PORT
variable being loaded? Is there something I'm missing?
Deno banner
DenoJoin
Chat about Deno, a modern runtime for JavaScript and TypeScript.
20,944Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

Why isn't this error caught?
Captain 𝗕𝗘𝗘𝗙🥩CCaptain 𝗕𝗘𝗘𝗙🥩 / help
3y ago
how do I add something to the deps.ts file that isn't in curly braces?
dan.the.discloserDdan.the.discloser / help
4y ago
Is there something similar to @nx/dependency-checks?
singingbananaSsingingbanana / help
6mo ago
Why is `mutate()` missing in `npm:@deno/kv`?
vwkdVvwkd / help
10mo ago