Packages

hono

4.13.19 · 16 Nov 2026MIT114.5M / weekRepositoryHomepagenpmAtom feed

Your version

4.6.0

11 Sep 2024Where it was published

4.13.19 is the newest release of 4.x.

In short

10 new1 fixed3 internal

Security

48 advisories affect 4.6.0; 4.13.16 fixes them

43 more

Release note

Hono v4.6.0 is now available!

One of the highlights of this release is the Context Storage Middleware. Let's introduce it.

Context Storage Middleware

Many users may have been waiting for this feature. The Context Storage Middleware uses AsyncLocalStorage to allow handling of the current Context object even outside of handlers.

For example, let’s define a Hono app with a variable message: string.

type Env = {
  Variables: {
    message: string
  }
}

const app = new Hono<Env>()

To enable Context Storage Middleware, register contextStorage() as middleware at the top and set the message value.

import { contextStorage } from 'hono/context-storage'

//...

app.use(contextStorage())

app.use(async (c, next) => {
  c.set('message', 'Hello!')
  await next()
})

getContext() returns the current Context object, allowing you to get the value of the message variable outside the handler.

import { getContext } from 'hono/context-storage'

app.get('/', (c) => {
  return c.text(getMessage())
})

// Access the variable outside the handler.
const getMessage = () => {
  return getContext<Env>().var.message
}

In the case of Cloudflare Workers, you can also access the Bindings outside the handler by using this middleware.

type Env = {
  Bindings: {
    KV: KVNamespace
  }
}

const app = new Hono<Env>()

app.use(contextStorage())

const setKV = (value: string) => {
  return getContext<Env>().env.KV.put('key', value)
}

Thanks @marceloverdijk !

New features

  • secureHeader: Add Permissions-Policy header to secure headers middleware #3314

  • cloudflare-pages: Enable c.env.eventContext in handleMiddleware #3332

  • websocket: Add generics type to WSContext #3337

  • jsx-renderer: Set Content-Encoding when stream is true #3355

  • serveStatic: Add precompressed option #3366

  • helper/streaming: Support Promise<string> or (async) JSX.Element in streamSSE #3344

  • context: Make fetch Response headers mutable #3318

  • serve-static: Add onFound option #3396

  • basic-auth: Added custom response message option #3371

  • bearer-auth: Added custom response message options #3372

Other changes

  • secure-headers: Optimize getPermissionsPolicyDirectives function

A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.