node-server icon indicating copy to clipboard operation
node-server copied to clipboard

Unified access to environment variables?

Open KGZM opened this issue 1 year ago • 3 comments

If c.env is intended to be for uniform environment access then we need some way to provide values to c.env when using the node-server.

I read issue #72, but the discussion there seems to miss the point. The problem isn't reading the environment, it's providing it.

Take a look at this search for c.env on the middleware repo.

The decision tree "If on cloudflare workers use c.env, else if on NodeJS use process.env" doesn't seem to work with shared middleware.

How is shared middleware supposed to work if c.env and process.env remain entirely separate?

KGZM avatar Feb 06 '24 18:02 KGZM

Hi @KGZM

We should use env() in hono/adapter.

import { env } from 'hono/adapter'

That, the code in the search results is not good. Many of these were created when there was no hono/adapter yet, and also assumed Cloudflare Workers. We should have used env().

yusukebe avatar Feb 08 '24 11:02 yusukebe

@yusukebe should c.env be deprecated and all first party packages migrated to use hono/adapter ?

thecotne avatar May 23 '24 15:05 thecotne

@thecotne

@yusukebe should c.env be deprecated and all first party packages migrated to use hono/adapter ?

No. We have to recommend using c.env for the Cloudflare Workers/Pages. It is now very familiar to the user. We don't need to stop using it.

yusukebe avatar Jun 03 '24 08:06 yusukebe