/Knowledge/sources/honojs__hono/examples/env-vars-src-index-ts--cff80b4b64aa.md
Example: env-vars/src/index.ts - hono-docs
Example: env vars/src/index.ts Source evidence: /Sources/honojs hono/provenance.md Canonical citation: https://raw.githubusercontent.com/honojs/examples/main...
Example: env-vars/src/index.ts
Source evidence: /Sources/honojs__hono/provenance.md Canonical citation: https://raw.githubusercontent.com/honojs/examples/main/env-vars/src/index.ts
Summary
import { Hono } from "hono"; import { Stripe } from "stripe"; type Variables = { stripe: Stripe; // Stripe Client }; type Bindings = { LIVEMODE: boolean; // Stripe Livemode true | false STRIPE_RK: string; // Stripe Restricted API Key STR...
Content
import { Hono } from "hono"; import { Stripe } from "stripe";
type Variables = { stripe: Stripe; // Stripe Client };
type Bindings = { LIVEMODE: boolean; // Stripe Livemode true | false STRIPE_RK: string; // Stripe Restricted API Key STRIPE_TK: string; // Stripe Test Key };
const app = new Hono<{ Bindings: Bindings; Variables: Variables }>();
app.use("*", async (c, next) => { // Determine if in a livemode or testmode context and set // the API Key accordingly const stripeKey: string = c.env.LIVEMODE ? c.env.STRIPE_RK : c.env.STRIPE_TK;
// Instantiate the Stripe client object const stripe = new Stripe(stripeKey, { maxNetworkRetries: 3, timeout: 30 * 1000, });
// Set the Stripe client to the Variable context object c.set("stripe", stripe);
await next(); });
app.get("/checkout", async (c) => {
Metadata
{
"chunk_index": 0,
"citation": "https://raw.githubusercontent.com/honojs/examples/main/env-vars/src/index.ts",
"coverage_role": "examples",
"qualified_title": "Hono / examples / env-vars/src/index.ts (1)",
"repo_path": "env-vars/src/index.ts",
"retrieved_at": "2026-07-02T05:51:01Z",
"section_index": 0,
"source_id": "/honojs/hono",
"source_type": "examples",
"target_label": "examples",
"title": "Example: env-vars/src/index.ts",
"upstream_url": "https://raw.githubusercontent.com/honojs/examples/main/env-vars/src/index.ts",
"version": "2026"
}