Skip to content

Is it possible to access env without using c.env? #2764

Answered by NicoPlyley
juniorforlife asked this question in Q&A
Discussion options

You must be logged in to vote

This is only the case when using Cloudflare Workers / Pages. This is not a limitation on Hono, but on how Cloudflare provides the environment variables. Here is how it is being handled in the background:

export default {
  async fetch(request, env) {
    myHonoApp.fetch(request, env)
};

On each request made to a worker, the environment variables are also sent, that is why they are only accessible in context, they are not made available globally.

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
3 replies
@juniorforlife
Comment options

@NicoPlyley
Comment options

@juniorforlife
Comment options

Answer selected by juniorforlife
Comment options

You must be logged in to vote
1 reply
@NicoPlyley
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants