Hono on Node.js

Overview

HTTP server for Hono on Node.js

This project is still experimental.

Hono is ultrafast web framework for Cloudflare Workers, Deno, and Bun. It's not for Node.js. BUT, there may be a case that you really want to run on Node.js. This library is an adaptor server that connects Hono and Node.js.

Hono is ultra fast, but not so fast on Node.js, because there is an overhead to adapt Hono's API to Node.js.

By the way, it is 2.x times faster than Express.

Install

You can install from npm registry:

npm install @honojs/node-server

Or

yarn add @honojs/node-server

Usage

The code:

import { serve } from '@honojs/node-server' // Write above `Hono`
import { Hono } from 'hono'

const app = new Hono()
app.get('/', (c) => c.text('Hono meets Node.js'))

serve(app)

And, run:

ts-node ./index.ts

Options

serve({
  fetch: app.fetch,
  port: 8787,
})

Related projects

Author

Yusuke Wada https://github.com/yusukebe

License

MIT

Comments
  • feat: @remix-run/web-fetch instead of undici

    feat: @remix-run/web-fetch instead of undici

    Hi! first of all, Hono is awesome, many thanks!. :)

    This PR aims to get performance boost by using @remix-run/web-fetch instead of undici.

    When I saw @yusukebe's tweet criticizing undici's performance, I wanted to experiment tests with other alternatives. At this point, I examined the approach of Remix, a framework that runs on both cloudflare and node.js.

    https://twitter.com/yusukebe/status/1569693510181486592

    opened by OnurGvnc 10
  • fix if statement bug in server

    fix if statement bug in server

    This change fixes a bug with the handling of HEAD requests.

    Previously we would never match on a HEAD request and thus incorrectly create a body to the request, which would throw an uncaught error

    opened by tavvy 2
  • serve static middleware for node

    serve static middleware for node

    As mentioned in issue #3, It is the serve static implementation for hono node server. I have also added hono's repo as dev dependency and linked it to easily import types and utils from the main repo.

    opened by that-ambuj 2
  • fix bug with encoded responses

    fix bug with encoded responses

    This change fixes how we write out a response body so that we can support encoded responses

    Previously we would cause a content encoding error by calling res.text() on responses even if they are encoded (br,gzip etc). Now we check if the response has the content-encoding header and use the read/write stream instead if it does.

    opened by tavvy 1
  • support multiple set-cookie headers in response

    support multiple set-cookie headers in response

    Fixes and edge case with multiple set-cookie headers in a single Response

    • multiple set-cookie headers in a single Response is valid
    • comma delimited set-cookie values in a single header are invalid (or rather they will not be picked up and set by the browser)
    • the res.headers Iterator returns the equivalent of res.headers.get('set-cookie') for the value, which is a comma delimited string (and thus invalid)
    • this fix will use res.headers.getAll('set-cookie') which returns an array of strings which is a valid value in response.setHeader https://nodejs.org/docs/latest-v18.x/api/http.html#responsesetheadername-value
    opened by tavvy 1
  • benchmark

    benchmark

    Hi, How do you compare performance with other node.js frameworks? Which tool or command do you use for benchmarking?

    I did something like https://github.com/OnurGvnc/hono-node-server/tree/dev/benchmarks

    { connections: 50, duration: 10 }
    
    fastify           105,594 req/seq
    hono               50,012 req/seq
    express            24,613 req/seq
    hono (undici)      17,648 req/seq
    

    with MacBookAir10,1 M1 16GB RAM 8 Core

    opened by OnurGvnc 4
Releases(v0.1.3)
  • v0.1.3(Dec 1, 2022)

    What's Changed

    • fix bug with encoded responses by @tavvy in https://github.com/honojs/node-server/pull/11

    Full Changelog: https://github.com/honojs/node-server/compare/v0.1.2...v0.1.3

    Source code(tar.gz)
    Source code(zip)
  • v0.1.2(Nov 29, 2022)

    What's Changed

    • fix if statement bug in server by @tavvy in https://github.com/honojs/node-server/pull/9
    • fix: handle the error thrown by fetchCallback by @yusukebe in https://github.com/honojs/node-server/pull/10

    Full Changelog: https://github.com/honojs/node-server/compare/v0.1.1...v0.1.2

    Source code(tar.gz)
    Source code(zip)
  • v0.1.1(Nov 27, 2022)

    What's Changed

    • refactor(serve-static): don't check c.res by @yusukebe in https://github.com/honojs/node-server/pull/6
    • support multiple set-cookie headers in response by @tavvy in https://github.com/honojs/node-server/pull/8

    New Contributors

    • @yusukebe made their first contribution in https://github.com/honojs/node-server/pull/6
    • @tavvy made their first contribution in https://github.com/honojs/node-server/pull/8

    Full Changelog: https://github.com/honojs/node-server/compare/v0.1.0...v0.1.1

    Source code(tar.gz)
    Source code(zip)
  • v0.1.0(Sep 30, 2022)

    What's Changed

    • update readme ad7d2f7
    • fixed type errors 1a4e8f8
    • feat: created serve-static middleware for node (#5) 433695a
    • chore: bump up Hono v2.2.1 b8e90d7

    New Contributors

    • @that-ambuj made their first contribution in https://github.com/honojs/node-server/pull/5

    Full Changelog: https://github.com/honojs/node-server/compare/v0.0.2...v0.1.0

    Source code(tar.gz)
    Source code(zip)
  • v0.0.2(Sep 15, 2022)

    What's Changed

    • feat: @remix-run/web-fetch instead of undici by @OnurGvnc in https://github.com/honojs/node-server/pull/1

    Commits

    • refactor: use RequestInit 7c37781
    • chore: remove example 6c0dade
    • docs: tweak README 955bb7a
    • docs: update readme 2cc5ae7
    • feat: @remix-run/web-fetch instead of undici (#1) 918f2c2
    • add tests, but it will fail a9a11b2
    • ci: setup up GitHub actions for CI 37bf345

    New Contributors

    • @OnurGvnc made their first contribution in https://github.com/honojs/node-server/pull/1

    Full Changelog: https://github.com/honojs/node-server/compare/v0.0.1...v0.0.2

    Source code(tar.gz)
    Source code(zip)
  • v0.0.1(Sep 11, 2022)

    Summary

    First release!!


    • chore: update package.json c3159dd
    • chore: add np 3b8e4bd
    • docs: update readme d4e5c93

    https://github.com/honojs/node-server/compare/f69a0c2959a9ec86d8222c3d30bf7357c4badc56...v0.0.1

    Full Changelog: https://github.com/honojs/node-server/commits/v0.0.1

    Source code(tar.gz)
    Source code(zip)
Owner
Hono
Ultrafast web framework for Cloudflare Workers, Deno, and Bun. Fast, but not only fast.
Hono
Example of a Cloudflare Pages server side rendering (SSR) project powered by Hono.

Hono SSR on Cloudflare Pages Example of a Cloudflare Pages server side rendered (SSR) project powered by Hono. This project demonstrates: Accessing en

Justin Noel 9 Nov 19, 2022
Node 18's node:test, as a node module

node-core-test This is a user-land port of node:test, the experimental test runner introduced in Node.js 18. This module makes it available in Node.js

Julian Gruber 62 Dec 15, 2022
Node-cli-starter - Basic starter kit for building Node CLI applications with TypeScript.

node-cli-starter Minimal starter kit for building Node CLI applications with TypeScript. Getting Started To get started clone repo locally and run npm

Cory Rylan 7 May 17, 2022
Apilytics for Node.js - Easy API analytics for Node backends

apilytics-node Apilytics is a service that lets you analyze operational, performance and security metrics from your APIs without infrastructure-level

Apilytics 9 Sep 2, 2022
This is a vanilla Node.js rest API created to show that it is possible to create a rest API using only vanilla Node.js

This is a vanilla Node.js rest API created to show that it is possible to create a rest API using only vanilla Node.js. But in most cases, I would recommend you to use something like Express in a production project for productivity purposes.

Eduardo Dantas 7 Jul 19, 2022
Inter Process Communication Module for node supporting Unix sockets, TCP, TLS, and UDP. Giving lightning speed on Linux, Mac, and Windows. Neural Networking in Node.JS

Inter Process Communication Module for node supporting Unix sockets, TCP, TLS, and UDP. Giving lightning speed on Linux, Mac, and Windows. Neural Networking in Node.JS

Node IPC 43 Dec 9, 2022
Node js package makes creating node jd dependincies files like Controllers,Entities and Repositories easier by executing a few instructions

Nodejs Studio Node js package makes creating node js project dependincies files like Controllers,Entities and Repositories easier by executing a few i

Syrian Open Source 9 Oct 12, 2022
Spin node create spin api for node

Links Contract api JS api @spinfi/core @spinfi/node @spinfi/node Spin node create spin api for node How to install yarn add @spinfi/node How to init i

Spin 6 Oct 18, 2022
:white_check_mark: The Node.js best practices list (March 2021)

Node.js Best Practices Follow us on Twitter! @nodepractices Read in a different language: CN, BR, RU, PL, JA, EU (ES, FR, HE, KR and TR in progress! )

Yoni Goldberg 85k Jan 9, 2023
A new Node.js resource built using Gatsby.js with React.js, TypeScript, and Remark.

Nodejs.dev Nodejs.dev site built using Gatsby.js with React.js, TypeScript, SCSS, and Remark. You can find the latest Figma design protype here. ?? Ge

Node.js 2.2k Jan 5, 2023
📗 How to write cross-platform Node.js code

How to write cross-platform Node.js code. Why you should care: according to the 2018 Node.js user survey, 24% of Node.js developers use Windows locall

ehmicky 1.3k Jan 3, 2023
Mina Node Monitor

Mina Node Monitor Mina Monitor is an extended graphical version of the mina client status command with additional indicators. This is a client-server

Serhii Pimenov 56 Dec 18, 2022
A crawler that extracts data from a dynamic webpage. Written in node js.

??️ Gumo "Gumo" (蜘蛛) is Japanese for "spider". Overview ?? A web-crawler (get it?) and scraper that extracts data from a family of nested dynamic webp

Nuthalapai Venkata Krishna Chaitanya 22 Sep 13, 2022
Play bad apple in Node.js

Bad Apple Nodejs Play Bad Apple in console with Nodejs! Requirements and Installation You can either git clone or download the repository as a zip. Se

null 10 Sep 8, 2022
Implementing hexagonal architecture on AWS Lambda with Node.js

Developing evolutionary architecture with AWS Lambda Context Agility enables you to evolve a workload quickly, adding new features, or introducing new

AWS Samples 95 Dec 20, 2022
A Simple Node.js Naive Bayes Library.

Idnaive Idnaive is A Simple Node.js Naive Bayes Library. ✅ Multilanguage Stemming (Indonesia + English) ✅ Out String Filter ✅ Punctuation Filter ✅ Fix

FNC 23 Oct 13, 2022
A Node.js library to calculate Uniswap V3 ratios (prices) from token pairs.

UniV3Prices A Node.js library to calculate Uniswap V3 ratios (prices) and liquidity (reserves). Features This library will allow you to: Calculate pri

Thanos Polychronakis 121 Dec 29, 2022
The AKE-less General Purpose Build System with JavaScript DSL for Node.js platform.

The AKE-less General Purpose Build System with JavaScript DSL for Node.js platform. Inspired by NUKE. This project is reaching a mature stage, althoug

Aleksej Komarov 33 Oct 16, 2022
Next-gen mobile first analytics server (think Mixpanel, Google Analytics) with built-in encryption supporting HTTP2 and gRPC. Node.js, headless, API-only, horizontally scaleable.

Introduction to Awacs Next-gen behavior analysis server (think Mixpanel, Google Analytics) with built-in encryption supporting HTTP2 and gRPC. Node.js

Socketkit 52 Dec 19, 2022