Packages

hono

4.13.19 · 16 Nov 2026MIT113.6M / weekRepositoryHomepagenpmAtom feed

Your version

2.2.0

21 Sep 2022Where it was published

2.7.8 is the newest release of 2.x.

In short

3 changed

Security

44 advisories affect 2.2.0; 4.13.16 fixes them

39 more

Release note

This release includes ES Module support, innovative new features, and some bug fixes. You will like it.

Summary

Support ES Module

We have distributed only CommonJS, but now we will distribute ES Module. ES Module is used when the library is imported using the import keyword. ESModule may improve performance and reduces bundle size.

StaticRouter and SmartRouter

Now we have a really smart router.

Added a simple router named "StaticRouter" that does not support dynamic routes. Now, we have there router: "TrieRouter", "RegExpRouter", and "StaticRouter".

And we introduce "SmartRouter".

SmartRouter picks the optimal router from three routers the first time it is accessed. Users can use the fastest router without explicitly specifying a router.

// Before this release.
// If we wanted to use optimal router, we have to specify it.
const app = new Hono({ router: new RegExpRouter() })
// This release.
// SmartRouter selects the fastest router automatically.
const app = new Hono()

StaticRouter is used for having only static routes. Otherwise, RegExpRouter will be used, but it has routing that RegExpRouter does not support, TrieRouter will be used.

Validator Middleware

New Validator Middleware as builtin middleware. This validator is magic.

app.post(
  '/posts',
  validator((v) => ({
    post: {
      id: v.json('post.id').asNumber().isRequired(),
      title: v.json('post.title').isRequired().isLength({ max: 100 }),
      published: v.json('post.published').asBoolean(),
      body: v.json('post.body').isOptional(),
    },
  })),
  (c) => {
    const res = c.req.valid()
    const post = res.post
    return c.text(`Post: ${post.id} is ${post.title}`)
  }
)

They will have "Types"! The value validated with asNumber() keyword will have "Type".

Not only that.

  • Easy to understand the result data because "declaring property name first".

  • Easy to writing rules. v.isLength(400) is better than v.isLength, 400.

  • Getting only "declared properties". Additional properties are always ignored. It's safe.

For more information: honojs.dev/docs/builtin-middleware/validator/

Validator Middleware was provided as third party Middleware: github.com/honojs/validator, it will be deprecated.


All changes are below:

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.